Classes
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.
Name Type Description interceptorFnLuCI.request.interceptorFn The interceptor function to register.
Returns:
Type Description LuCI.request.interceptorFn The registered function. -
Turn the given relative URL into an absolute URL if necessary.
Name Type Description urlstring The URL to convert.
Returns:
Type Description string The absolute URL derived from the given one, or the original URL if it already was absolute. -
get(url, options){Promise.<LuCI.response>}
-
Initiate an HTTP GET request to the given target.
Name Type Description urlstring The URL to request.
optionsLuCI.request.RequestOptions optional Additional options to configure the request.
Returns:
Type Description Promise.<LuCI.response> The resulting HTTP response. -
post(url, data, options){Promise.<LuCI.response>}
-
Initiate an HTTP POST request to the given target.
Name Type Description urlstring The URL to request.
data* optional The request data to send, see
LuCI.request.RequestOptionsfor details.optionsLuCI.request.RequestOptions optional Additional options to configure the request.
Returns:
Type Description Promise.<LuCI.response> The resulting HTTP response. -
Remove an HTTP response interceptor function. The passed function value must be the very same value that was used to register the function.
Name Type Description interceptorFnLuCI.request.interceptorFn The interceptor function to remove.
Returns:
Type Description boolean Returns trueif any function has been removed, elsefalse. -
request(target, options){Promise.<LuCI.response>}
-
Initiate an HTTP request to the given target.
Name Type Description targetstring The URL to request.
optionsLuCI.request.RequestOptions optional Additional options to configure the request.
Returns:
Type Description Promise.<LuCI.response> The resulting HTTP response.
Type Definitions
-
Interceptor functions are invoked whenever an HTTP reply is received, in the order these functions have been registered.
Name Type Description resLuCI.response The HTTP response object
-
LuCI.request.RequestOptionsObject
-
Properties:
Name Type Argument Default Description methodstring <optional>
GET The HTTP method to use, e.g.
GETorPOST.queryObject.<string, (Object|string)> <optional>
Query string data to append to the URL. Non-string values of the given object will be converted to JSON.
cacheboolean <optional>
false Specifies whether the HTTP response may be retrieved from cache.
usernamestring <optional>
Provides a username for HTTP basic authentication.
passwordstring <optional>
Provides a password for HTTP basic authentication.
timeoutnumber <optional>
Specifies the request timeout in milliseconds.
credentialsboolean <optional>
false Whether to include credentials such as cookies in the request.
responseTypestring <optional>
text Overrides the request response type. Valid values or
textto interpret the response as UTF-8 string orblobto handle the response as binaryBlobdata.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.
headerObject.<string, string> <optional>
Specifies HTTP headers to set for the request.
progressfunction <optional>
An optional request callback function which receives ProgressEvent instances as sole argument during the HTTP request transfer.