Home Identifier Source Repository
public class | source

WebAPI

A helper class for working with the REST API.

In all cases, no attempt is made to trap errors. RequestPromises are returned from each method. It's up to the caller to handle rejection.

Example:

import WebAPI from "./WebAPI";

WebAPI.get("/admin/products.json")
  .then(json => console.log(json))
  .catch(error => console.log(error.message));

Method Summary

Public Methods
public

delete(url: string, options: object): RequestPromise

Performs a DELETE request for the given URL and options

public

get(url: string, options: object): RequestPromise

Performs a GET request for the given URL and options

public

post(url: string, resource: object, options: object): RequestPromise

Performs a POST request for the given URL and options, passing the resource as the request body

public

put(url: string, resource: object, options: object): RequestPromise

Performs a PUT request for the given URL and options, passing the resource as the request body

Public Methods

public delete(url: string, options: object): RequestPromise source

Performs a DELETE request for the given URL and options

Params:

NameTypeAttributeDescription
url string

the (relative) URL to get (e.g. /admin/products/1.json)

options object
  • optional

options to pass along to the fetch call

Return:

RequestPromise

public get(url: string, options: object): RequestPromise source

Performs a GET request for the given URL and options

Params:

NameTypeAttributeDescription
url string

the (relative) URL to get (e.g. /admin/products.json)

options object
  • optional

options to pass along to the fetch call

Return:

RequestPromise

public post(url: string, resource: object, options: object): RequestPromise source

Performs a POST request for the given URL and options, passing the resource as the request body

Params:

NameTypeAttributeDescription
url string

the (relative) URL to get (e.g. /admin/products.json)

resource object
  • optional

the resource to post as the request body

options object
  • optional

options to pass along to the fetch call

Return:

RequestPromise

public put(url: string, resource: object, options: object): RequestPromise source

Performs a PUT request for the given URL and options, passing the resource as the request body

Params:

NameTypeAttributeDescription
url string

the (relative) URL to get (e.g. /admin/products/1.json)

resource object
  • optional

the resource to post as the request body

options object
  • optional

options to pass along to the fetch call

Return:

RequestPromise