# 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

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

# Returns

# .post()

Send a HTTP post request to a URL

# Parameters

# Returns

# .put()

Send a HTTP put request to a URL

# Parameters

# Returns

# .patch()

Send a HTTP patch request to a URL

# Parameters

# Returns

# .delete()

Send a HTTP delete request to a URL

# Parameters

# Returns