Reference Source
import WLResourceRequest from 'react-native-ibm-mobilefirst'
public class | source

WLResourceRequest

This class encapsulates a resource request. The resource can be an adapter that is deployed to an instance of MobileFirst Server, or a resource on an external resource server. The class provides several send methods with different inputs for the body of a request. A successful response is any response with a status in the 2xx range from the server.
A response with a 4xx or 5xx status from the server is considered a failure.

Static Member Summary

Static Public Members
public static get
public static get
public static get
public static get
public static get
public static get

Static Method Summary

Static Public Methods
public static

Constructor Summary

Public Constructor
public

constructor(url: string, method: string, timeout: number, scope: string)

Create a new ResourceRequest object to fetch data from a resource endpoint.

Method Summary

Public Methods
public

addHeader(name: string, value: string)

Adds a header to this resource request.

public

Get a list of all the headers added to this request

public

async getHeaders(headerName: string): Promise<Array>

Get a list of values for a given header

public

Get the HTTP method of this resource request.

public

Get all the query parameters that are added to this request.

public

Get the query string of this request.

public

async getTimeout(): number

Get the timeout for this resource request.

public

async getUrl(): string

Returns the URL for this resource request.

public

removeHeaders(headerName: string)

Removes headers with the specified name for this resource request.

public

async send(): Promise<Map, String>

Initiate a request to the resource without any content in the body.

public

Initiate a request to the resource with the specified form parameters in the body.

public

async sendWithJSON(jsonObject: Object): Promise<Map, String>

Initiate a request to the resource with the specified JSON content in the body.

public

Initiate a request to the resource with raw text in the body.

public

setHeaders(headers: Object)

Sets the specified headers for this resource request.

public

Set the query parameters that should be added to this request.

public

setTimeout(timeoutInMilliseconds: number)

Sets the expiration period (timeout) for this resource request.

Static Public Members

public static get DELETE: string source

public static get GET: string source

public static get OPTIONS: string source

public static get POST: string source

public static get PUT: string source

public static get TRACE: string source

Static Public Methods

public static HEAD(): string source

Return:

string

Public Constructors

public constructor(url: string, method: string, timeout: number, scope: string) source

Create a new ResourceRequest object to fetch data from a resource endpoint.

Params:

NameTypeAttributeDescription
url string

The URL of the resource - either as an absolute URL or a relative URL.

method string

The HTTP method to call the resource. Use WLResourceRequest.GET, WLResourceRequest.POST, WLResourceRequest.HEAD, WLResourceRequest.PUT, WLResourceRequest.DELETE, WLResourceRequest.OPTIONS, WLResourceRequest.TRACE

timeout number

Optional. The interval in milliseconds after which the call to the resource should time out. The default timeout is 30 seconds.

scope string

Optional. The scope protecting the particular resource.

Public Methods

public addHeader(name: string, value: string) source

Adds a header to this resource request. This method allows response headers to have multiple values.

Params:

NameTypeAttributeDescription
name string

The name of the header to add to the request.

value string

The value of the header to add to the request.

public async getAllHeaders(): Promise<Object> source

Get a list of all the headers added to this request

Return:

Promise<Object>

A list of all HTTP headers that are added to this request. Note that each header can have one or more values.

public async getHeaders(headerName: string): Promise<Array> source

Get a list of values for a given header

Params:

NameTypeAttributeDescription
headerName string

The name of the header

Return:

Promise<Array>

An array of values for the given header name.

public async getMethod(): Promise<string> source

Get the HTTP method of this resource request.

Return:

Promise<string>

The HTTP method of the resource request.

public async getQueryParameters(): Promise<Object> source

Get all the query parameters that are added to this request.

Return:

Promise<Object>

A JSON object with query parameters

public async getQueryString(): Promise<string> source

Get the query string of this request.

Return:

Promise<string>

A string containing the query parameters as a query string.

public async getTimeout(): number source

Get the timeout for this resource request.

Return:

number

The timeout of this request in milliseconds.

public async getUrl(): string source

Returns the URL for this resource request.

Return:

string

The absolute URL of the resource request.

public removeHeaders(headerName: string) source

Removes headers with the specified name for this resource request.

Params:

NameTypeAttributeDescription
headerName string

The name of the header to remove.

public async send(): Promise<Map, String> source

Initiate a request to the resource without any content in the body.

Return:

Promise<Map, String>

If success, a map with the response from the server. The map contain following key strings. "responseText" - Original response text from the server. "responseJSON" - in case the response is a JSON response, otherwise map will not have the field. "userInfo" - user information. "headers" - Retrieves the headers from the response. "status" - HTTP status from the response If failure, more information about the error.

public async sendWithFormParameters(formParams: Object): Promise<Map, String> source

Initiate a request to the resource with the specified form parameters in the body.

Params:

NameTypeAttributeDescription
formParams Object

The JSON object of form parameters in name-value pairs

Return:

Promise<Map, String>

If success, a map with the response from the server. The map contain following key strings. "responseText" - Original response text from the server. "responseJSON" - in case the response is a JSON response, otherwise map will not have the field. "userInfo" - user information. "headers" - Retrieves the headers from the response. "status" - HTTP status from the response If failure, more information about the error.

public async sendWithJSON(jsonObject: Object): Promise<Map, String> source

Initiate a request to the resource with the specified JSON content in the body.

Params:

NameTypeAttributeDescription
jsonObject Object

The body of the request in JSON format.

Return:

Promise<Map, String>

If success, a map with the response from the server. The map contain following key strings. "responseText" - Original response text from the server. "responseJSON" - in case the response is a JSON response, otherwise map will not have the field. "userInfo" - user information. "headers" - Retrieves the headers from the response. "status" - HTTP status from the response If failure, more information about the error.

public async sendWithRequestBody(body: string): Promise<Map, String> source

Initiate a request to the resource with raw text in the body.

Params:

NameTypeAttributeDescription
body string

The body that is part of the request.

Return:

Promise<Map, String>

If success, a map with the response from the server.The map contain following key strings. "responseText" - Original response text from the server. "responseJSON" - in case the response is a JSON response, otherwise map will not have the field. "userInfo" - user information. "headers" - Retrieves the headers from the response. "status" - HTTP status from the response If failure, more information about the error.

public setHeaders(headers: Object) source

Sets the specified headers for this resource request. For a header that is already set, the new value overwrites the previous value.

Params:

NameTypeAttributeDescription
headers Object

A JSON object containing a map of all headers to be set for this request.

public setQueryParameters(params: Object) source

Set the query parameters that should be added to this request.

Params:

NameTypeAttributeDescription
params Object

A JSON object containing name value pairs of query parameters that should be added to this request.

public setTimeout(timeoutInMilliseconds: number) source

Sets the expiration period (timeout) for this resource request.

Params:

NameTypeAttributeDescription
timeoutInMilliseconds number

The timeout in milliseconds