# Introduction
Sorry!
This page is not up to standards, improvements need to be made inline with the rest of the documentation.
# API
This is Pulse's integrated fetch API. It's a wrapper around Fetch, which is native to the browser environment.
const MyAPI = App.API()
# Setup
The API class accepts a config object.
const MyAPI = App.API({
options: {
headers: {
'content-type': 'application/json, text/plain' // this is not necessary
}
},
baseURL: 'https://api.mysite.co', // default: 'https://localhost'
path: '/api', // default: '/'
timeout: 20000, // default: infinite
requestIntercept: request => {
// do something
},
responseIntercept: response => {
// do something
}
});
# API Config Parameters
- options (RequestOptions) optional - This has all the same options as the js fetch function. Nothing is required, but it is recommended depending on your setup
- baseURL (string) optional - The base url for the endpoint which defaults to your local system.
- path (string) optional - The path for the endpoint which defaults to root
- timeout (number) optional - A timeout for the fetch. By default it does not have a timeout so if you are unsure if the request will complete, you should set this.
- requestIntercept (Function) optional - An intercept function on request sent
- responseIntercept (Function) optional - An intercept function on response received
# Request Options
- headers (string) optional - Any headers you want to add to your request
- mode (string) optional - The mode you want to use for the request, e.g.,
cors
,no-cors
, orsame-origin
. - credentials (string) optional - The request credentials you want to use for the request:
omit
,same-origin
, orinclude
. - cache (string) optional - The cache mode (opens new window) you want to use for the request.
- redirect (string) optional - The redirect mode to use:
follow
(automatically follow redirects),error
(abort with an error if a redirect occurs), ormanual
(handle redirects manually). - referrerPolicy (string) optional - A string specifying the referrer of the request. This can be a same-origin URL, about:client, or an empty string.
- integrity (string) optional - Contains the subresource integrity (opens new window) value of the request
- keepalive (string) optional - The keepalive option can be used to allow the request to outlive the page.
- signal (AbortSignal) optional - An AbortSignal (opens new window) object instance; allows you to communicate with a fetch request and abort it if desired via an AbortController (opens new window).
Note: Refer to Fetch Documentation for More Info.
For more information on the options available, please refer to the Fetch API (opens new window) page, as this is what is used under the hood.
# Response
Every API method returns a pulse response which allows for easy interpretation and manipulation of the incoming data.
interface PulseResponse<DataType = any> {
data: Object;
timedout?: boolean;
status: number;
raw?: Response;
type?: string;
}
# Methods
# .with()
This function allows you to override the API config and request options. It returns a modified instance of the original API with the options in the config parameter overriding the original config options.
# Parameters
# Returns
# .get()
Send a HTTP get request to a url
# Parameters
- path (string) - The URL path to use
- options (RequestOptions) optional - has the same options as fetch
# Returns
# .post()
Send a HTTP post request to a URL
# Parameters
- path (string) - The URL path to use
- data (Object) - The data to send as the body of the post request
- options (RequestOptions) optional -
# Returns
# .put()
Send a HTTP put request to a URL
# Parameters
- path (string) - The URL path to use
- data (Object) - The data to send as the body of the put request
- options (RequestOptions) optional -
# Returns
# .patch()
Send a HTTP patch request to a URL
# Parameters
- path (string) - The URL path to use
- data (Object) - The data to send as the body of the patch request
- options (RequestOptions) optional -
# Returns
# .delete()
Send a HTTP delete request to a URL
# Parameters
- path (string) - The URL path to use
- data (Object) - The data to send as the body of the delete request
- options (RequestOptions) optional -
# Returns
← Core Persisting Data →