UNPKG

1.29 kBMarkdownView Raw
1# CORE HTTP
2
3A simple HTTP client.
4
5```bash
6yarn add @procore/core-http
7```
8
9This simple wrapper over native fetch makes interacting with the Procore API a little easier. By default, it injects a CSRF token from known places when working from inside of an Micro Front End, or in a Hydra Client, but takes in a second parameter that helps you override any value you would need to customize.
10
11## Usage
12
13<details>
14 <summary>Simple Example</summary>
15
16```tsx
17import { request } from '@procore/core-http'
18
19function ExampleRequest() {
20 request('/some-url-here')
21 .then((response) => console.log(response))
22 .catch((err) => console.error(err))
23}
24```
25
26</details>
27
28<details>
29 <summary>With baseUrl option</summary>
30
31```tsx
32import { request } from '@procore/core-http'
33
34function ExampleRequest() {
35 request('/some-url-here', { baseUrl: 'https://www.example.com' })
36 .then((response) => console.log(response))
37 .catch((err) => console.error(err))
38}
39```
40
41</details>
42
43<details>
44 <summary>Automatically convert from json response with a text fallback.</summary>
45
46```tsx
47import { requestJSON } from '@procore/core-http'
48
49function ExampleRequest() {
50 requestJSON('/some-url-here.json')
51 .then((response) => console.log(response))
52 .catch((err) => console.error(err))
53}
54```
55
56</details>