Methods
-
clearDefaultHeaders()
-
Clears all configured default headers.
Returns:
This HTTP agent.
- Type
- HttpAgent
-
delete(url, data [, options])
-
Sends an HTTP DELETE request to the specified URL, sending the provided data as the request body. If an object is provided as the request data, the data will be JSON-encoded. Sending other primitive non-string values as the request body is not supported.
Parameters:
Name Type Argument Description url
string The URL to which the request should be made.
data
string | Object.<string, *> The data to send to the server as the request body.
options
HttpAgent~RequestOptions <optional>
Optional request options.
Returns:
A promise that resolves to the response.
- Type
- Promise.<HttpAgent~Response>
-
get(url, data [, options])
-
Sends an HTTP GET request to the specified URL, sending the provided data as query parameters.
Parameters:
Name Type Argument Description url
string The URL to which the request should be made.
data
Object.<string, (boolean|number|string)> The data to send to the server as query parameters.
options
HttpAgent~RequestOptions <optional>
Optional request options.
Returns:
A promise that resolves to the response.
- Type
- Promise.<HttpAgent~Response>
-
getCacheKey(method, url, data)
-
Generates a cache key to use for identifying a request to the specified URL using the specified HTTP method, submitting the provided data.
Parameters:
Name Type Description method
string The HTTP method used by the request.
url
string The URL to which the request is sent.
data
Object.<string, string> The data associated with the request. These can be either the query parameters or request body data.
Returns:
The key to use for identifying such a request in the cache.
- Type
- string
-
patch(url, data [, options])
-
Sends an HTTP PATCH request to the specified URL, sending the provided data as the request body. If an object is provided as the request data, the data will be JSON-encoded. Sending other primitive non-string values as the request body is not supported.
Parameters:
Name Type Argument Description url
string The URL to which the request should be made.
data
string | Object.<string, *> The data to send to the server as the request body.
options
HttpAgent~RequestOptions <optional>
Optional request options.
Returns:
A promise that resolves to the response.
- Type
- Promise.<HttpAgent~Response>
-
post(url, data [, options])
-
Sends an HTTP POST request to the specified URL, sending the provided data as the request body. If an object is provided as the request data, the data will be JSON-encoded. Sending other primitive non-string values as the request body is not supported.
Parameters:
Name Type Argument Description url
string The URL to which the request should be made.
data
string | Object.<string, *> The data to send to the server as the request body.
options
HttpAgent~RequestOptions <optional>
Optional request options.
Returns:
A promise that resolves to the response.
- Type
- Promise.<HttpAgent~Response>
-
put(url, data [, options])
-
Sends an HTTP PUT request to the specified URL, sending the provided data as the request body. If an object is provided as the request data, the data will be JSON-encoded. Sending other primitive non-string values as the request body is not supported.
Parameters:
Name Type Argument Description url
string The URL to which the request should be made.
data
string | Object.<string, *> The data to send to the server as the request body.
options
HttpAgent~RequestOptions <optional>
Optional request options.
Returns:
A promise that resolves to the response.
- Type
- Promise.<HttpAgent~Response>
-
setDefaultHeader(header, value)
-
Sets the specified header to be sent with every subsequent HTTP request, unless explicitly overridden by request options.
Parameters:
Name Type Description header
string The name of the header.
value
string The header value. To provide multiple values, separate them with commas (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2).
Returns:
This HTTP agent.
- Type
- HttpAgent
Type Definitions
-
RequestOptions
-
Options for a request sent using the HTTP agent.
Type:
- Object
Properties:
Name Type Argument Description timeout
number <optional>
Specifies the request timeout in milliseconds.
ttl
number <optional>
Specified how long the request may be cached in milliseconds.
repeatRequest
number <optional>
Specifies the maximum number of tries to repeat the request if the request fails.
headers
Object.<string, string> <optional>
Sets the additional request headers (the keys are case-insensitive header names, the values are header values).
fetchOptions
Object.<string, *> <optional>
Sets the fetch request options.
cache
boolean <optional>
Flag that enables caching the HTTP request (enabled by default, also applies to requests in progress).
withCredentials
boolean <optional>
Flag that indicates whether the request should be made using credentials such as cookies or authorization headers.
listeners
Object <optional>
Listeners for request events.
postProcessor
function <optional>
Response post-processor applied just before the response is stored in the cache and returned.
-
Response
-
A response from the server.
Type:
- Object
Properties:
Name Type Description status
number The HTTP response status code.
body
* The parsed response body, parsed as JSON.
params
HttpProxy~RequestParams The original request params.
headers
Object.<string, string> The response HTTP headers.
cached
boolean Whether or not the response has been cached.