Home Reference Source
import Request from '@fnndsc/chrisstoreapi'
public class | source

Request

Http request object.

Static Method Summary

Static Public Methods
public static

runAsyncTask(taskGenerator: function*())

Helper method to run an asynchronous task defined by a task generator function.

Static Private Methods
private static

Internal method to make an axios request.

private static

Internal method to handle errors produced by HTTP requests.

Constructor Summary

Public Constructor
public

constructor(auth: Object, contentType: string, timeout: number)

Constructor

Member Summary

Public Members
public
public
public

Method Summary

Public Methods
public

Perform a DELETE request.

public

get(url: string, params: Object): Object

Perform a GET request.

public

post(url: string, data: Object, uploadFileObj: Object): Object

Perform a POST request.

public

put(url: string, data: Object, uploadFileObj: Object): Object

Perform a PUT request.

Private Methods
private

_getConfig(url: string, method: string): Object

Internal method to create a config file for axios.

private

_postOrPut(requestMethod: string, url: string, data: Object, uploadFileObj: Object): Object

Internal method to make either a POST or PUT request.

Static Public Methods

public static runAsyncTask(taskGenerator: function*()) source

Helper method to run an asynchronous task defined by a task generator function.

Params:

NameTypeAttributeDescription
taskGenerator function*()

generator function

Static Private Methods

private static _callAxios(config: Object): Object source

Internal method to make an axios request.

Params:

NameTypeAttributeDescription
config Object

axios configuration object

Return:

Object

JS Promise, resolves to an axios reponse object

private static _handleRequestError(error: Object) source

Internal method to handle errors produced by HTTP requests.

Params:

NameTypeAttributeDescription
error Object

axios error object

Throw:

RequestException

throw error

Public Constructors

public constructor(auth: Object, contentType: string, timeout: number) source

Constructor

Params:

NameTypeAttributeDescription
auth Object

authentication object

auth.token string

authentication token

contentType string

request content type

timeout number
  • optional
  • default: 30000

request timeout

Public Members

public auth: Object source

public contentType: string source

public timeout: number source

Public Methods

public delete(url: string): Object source

Perform a DELETE request.

Params:

NameTypeAttributeDescription
url string

url of the resource

Return:

Object

JS Promise, resolves to an axios reponse object

public get(url: string, params: Object): Object source

Perform a GET request.

Params:

NameTypeAttributeDescription
url string

url of the resource

params Object
  • nullable: true

search parameters

Return:

Object

JS Promise, resolves to an axios reponse object

public post(url: string, data: Object, uploadFileObj: Object): Object source

Perform a POST request.

Params:

NameTypeAttributeDescription
url string

url of the resource

data Object

JSON data object

uploadFileObj Object
  • nullable: true

custom object with a property with the same name as the API descriptor corresponding to the file and whose value is the file blob

Return:

Object

JS Promise, resolves to an axios reponse object

public put(url: string, data: Object, uploadFileObj: Object): Object source

Perform a PUT request.

Params:

NameTypeAttributeDescription
url string

url of the resource

data Object

JSON data object

uploadFileObj Object
  • nullable: true

custom object with a property with the same name as the API descriptor corresponding to the file and whose value is the file blob

Return:

Object

JS Promise, resolves to an axios reponse object

Private Methods

private _getConfig(url: string, method: string): Object source

Internal method to create a config file for axios.

Params:

NameTypeAttributeDescription
url string

url of the resource

method string

request verb

Return:

Object

axios configuration object

private _postOrPut(requestMethod: string, url: string, data: Object, uploadFileObj: Object): Object source

Internal method to make either a POST or PUT request.

Params:

NameTypeAttributeDescription
requestMethod string

either 'post' or 'put'

url string

url of the resource

data Object

JSON data object

uploadFileObj Object
  • nullable: true

custom object with a property with the same name as the API descriptor corresponding to the file and whose value is the file blob

Return:

Object

JS Promise, resolves to an axios reponse object