Home Reference Source
import Request from '@fnndsc/chrisapi'
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

_callAxios(config: AxiosRequestConfig): Promise<AxiosResponse>

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

delete(url: string): Promise<AxiosResponse>

Perform a DELETE request.

public

get(url: string, params: Object): Promise<AxiosResponse>

Perform a GET request.

public

post(url: string, data: Object, uploadFileObj: Object): Promise<AxiosResponse>

Perform a POST request.

public

put(url: string, data: Object, uploadFileObj: Object): Promise<AxiosResponse>

Perform a PUT request.

Private Methods
private

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

Internal method to create a config file for axios.

private

_postOrPut(requestMethod: string, url: string, data: Object, uploadFileObj: Object): Promise<AxiosResponse>

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: AxiosRequestConfig): Promise<AxiosResponse> source

Internal method to make an axios request.

Params:

NameTypeAttributeDescription
config AxiosRequestConfig

axios configuration object

Return:

Promise<AxiosResponse>

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): Promise<AxiosResponse> source

Perform a DELETE request.

Params:

NameTypeAttributeDescription
url string

url of the resource

Return:

Promise<AxiosResponse>

JS Promise, resolves to an axios reponse object

public get(url: string, params: Object): Promise<AxiosResponse> source

Perform a GET request.

Params:

NameTypeAttributeDescription
url string

url of the resource

params Object
  • nullable: true

search parameters

Return:

Promise<AxiosResponse>

JS Promise, resolves to an axios reponse object

public post(url: string, data: Object, uploadFileObj: Object): Promise<AxiosResponse> 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:

Promise<AxiosResponse>

JS Promise, resolves to an axios reponse object

public put(url: string, data: Object, uploadFileObj: Object): Promise<AxiosResponse> 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:

Promise<AxiosResponse>

JS Promise, resolves to an axios reponse object

Private Methods

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

Internal method to create a config file for axios.

Params:

NameTypeAttributeDescription
url string

url of the resource

method string

request verb

Return:

AxiosRequestConfig

axios configuration object

private _postOrPut(requestMethod: string, url: string, data: Object, uploadFileObj: Object): Promise<AxiosResponse> 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:

Promise<AxiosResponse>

JS Promise, resolves to an axios reponse object