Class: Request

LuCI.Request

The Request class allows initiating HTTP requests and provides utilities for dealing with responses.

Source:

Classes

poll

Methods

addInterceptor(interceptorFn) → {LuCI.Request.interceptorFn}

Register an HTTP response interceptor function. Interceptor functions are useful to perform default actions on incoming HTTP responses, such as checking for expired authentication or for implementing request retries before returning a failure.

Parameters:
Name Type Description
interceptorFn LuCI.Request.interceptorFn

The interceptor function to register.

Source:
Returns:

The registered function.

Type
LuCI.Request.interceptorFn

expandURL(url) → {string}

Turn the given relative URL into an absolute URL if necessary.

Parameters:
Name Type Description
url string

The URL to convert.

Source:
Returns:

The absolute URL derived from the given one, or the original URL if it already was absolute.

Type
string

get(target, optionsopt) → {Promise.<LuCI.Response>}

Initiate an HTTP GET request to the given target.

Parameters:
Name Type Attributes Description
target string

The URL to request.

options LuCI.Request.RequestOptions <optional>

Additional options to configure the request.

Source:
Returns:

The resulting HTTP response.

Type
Promise.<LuCI.Response>

post(target, dataopt, optionsopt) → {Promise.<LuCI.Response>}

Initiate an HTTP POST request to the given target.

Parameters:
Name Type Attributes Description
target string

The URL to request.

data * <optional>

The request data to send, see LuCI.Request.RequestOptions for details.

options LuCI.Request.RequestOptions <optional>

Additional options to configure the request.

Source:
Returns:

The resulting HTTP response.

Type
Promise.<LuCI.Response>

removeInterceptor(interceptorFn) → {boolean}

Remove an HTTP response interceptor function. The passed function value must be the very same value that was used to register the function.

Parameters:
Name Type Description
interceptorFn LuCI.Request.interceptorFn

The interceptor function to remove.

Source:
Returns:

Returns true if any function has been removed, else false.

Type
boolean

request(target, optionsopt) → {Promise.<LuCI.Response>}

Initiate an HTTP request to the given target.

Parameters:
Name Type Attributes Description
target string

The URL to request.

options LuCI.Request.RequestOptions <optional>

Additional options to configure the request.

Source:
Returns:

The resulting HTTP response.

Type
Promise.<LuCI.Response>

Type Definitions

interceptorFn(res)

Interceptor functions are invoked whenever an HTTP reply is received, in the order these functions have been registered.

Parameters:
Name Type Description
res LuCI.Response

The HTTP response object

Source:

RequestOptions

Type:
  • Object
Properties:
Name Type Attributes Default Description
method string <optional>
GET

The HTTP method to use, e.g. GET or POST.

query Object.<string, (Object|string)> <optional>

Query string data to append to the URL. Non-string values of the given object will be converted to JSON.

cache boolean <optional>
false

Specifies whether the HTTP response may be retrieved from cache.

username string <optional>

Provides a username for HTTP basic authentication.

password string <optional>

Provides a password for HTTP basic authentication.

timeout number <optional>

Specifies the request timeout in seconds.

credentials boolean <optional>
false

Whether to include credentials such as cookies in the request.

content * <optional>

Specifies the HTTP message body to send along with the request. If the value is a function, it is invoked and the return value used as content, if it is a FormData instance, it is used as-is, if it is an object, it will be converted to JSON, in all other cases it is converted to a string.

header Object.<string, string> <optional>

Specifies HTTP headers to set for the request.

progress function <optional>

An optional request callback function which receives ProgressEvent instances as sole argument during the HTTP request transfer.

Source: