UNPKG

@procore/core-http

Version:

A HTTP Client

57 lines (40 loc) 1.29 kB
# CORE HTTP A simple HTTP client. ```bash yarn add @procore/core-http ``` This 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. ## Usage <details> <summary>Simple Example</summary> ```tsx import { request } from '@procore/core-http' function ExampleRequest() { request('/some-url-here') .then((response) => console.log(response)) .catch((err) => console.error(err)) } ``` </details> <details> <summary>With baseUrl option</summary> ```tsx import { request } from '@procore/core-http' function ExampleRequest() { request('/some-url-here', { baseUrl: 'https://www.example.com' }) .then((response) => console.log(response)) .catch((err) => console.error(err)) } ``` </details> <details> <summary>Automatically convert from json response with a text fallback.</summary> ```tsx import { requestJSON } from '@procore/core-http' function ExampleRequest() { requestJSON('/some-url-here.json') .then((response) => console.log(response)) .catch((err) => console.error(err)) } ``` </details>