HttpAgent

http/HttpAgent~ HttpAgent

The HttpAgent defines unifying API for sending HTTP requests at both client-side and server-side.

Methods

clearDefaultHeaders() → {HttpAgent}

Source:
Clears all configured default headers.
Returns:
This HTTP agent.
Type
HttpAgent

delete(url, data, optionsopt) → {Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>}

Source:
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 Attributes 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 Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails. The headers field sets the additional request headers (the keys are case-insensitive header names, the values are header values). The cache flag enables caching the HTTP request (enabled by default, also applies to requests in progress). The withCredentials flag indicates whether the request should be made using credentials such as cookies or authorization headers. The listeners Add listeners for request. The postProcessor is method for changing agent response before than the response is saved in cache and returned in promise.
Returns:
A promise that resolves to the response. The response body will be parsed according to the Content-Type response header's value.
Type
Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>

get(url, data, optionsopt) → {Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>}

Source:
Sends an HTTP GET request to the specified URL, sending the provided data as query parameters.
Parameters:
Name Type Attributes 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 Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails. The headers field sets the additional request headers (the keys are case-insensitive header names, the values are header values). The cache flag enables caching the HTTP request (enabled by default, also applies to requests in progress). The withCredentials flag indicates whether the request should be made using credentials such as cookies or authorization headers. The listeners Add listeners for request. The postProcessor is method for changing agent response before than the response is saved in cache and returned in promise.
Returns:
A promise that resolves to the response. The response body will be parsed according to the Content-Type response header's value.
Type
Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>

getCacheKey(method, url, data) → {string}

Source:
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, optionsopt) → {Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>}

Source:
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 Attributes 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 Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails. The headers field sets the additional request headers (the keys are case-insensitive header names, the values are header values). The cache flag enables caching the HTTP request (enabled by default, also applies to requests in progress). The withCredentials flag indicates whether the request should be made using credentials such as cookies or authorization headers. The listeners Add listeners for request. The postProcessor is method for changing agent response before than the response is saved in cache and returned in promise.
Returns:
A promise that resolves to the response. The response body will be parsed according to the Content-Type response header's value.
Type
Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>

post(url, data, optionsopt) → {Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>}

Source:
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 Attributes 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 Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails. The headers field sets the additional request headers (the keys are case-insensitive header names, the values are header values). The cache flag enables caching the HTTP request (enabled by default, also applies to requests in progress). The withCredentials flag indicates whether the request should be made using credentials such as cookies or authorization headers. The listeners Add listeners for request. The postProcessor is method for changing agent response before than the response is saved in cache and returned in promise.
Returns:
A promise that resolves to the response. The response body will be parsed according to the Content-Type response header's value.
Type
Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>

put(url, data, optionsopt) → {Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>}

Source:
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 Attributes 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 Object <optional>
Optional request options. The timeout specifies the request timeout in milliseconds, the ttl specified how long the request may be cached in milliseconds, the repeatRequest specifies the maximum number of tries to repeat the request if the request fails. The headers field sets the additional request headers (the keys are case-insensitive header names, the values are header values). The cache flag enables caching the HTTP request (enabled by default, also applies to requests in progress). The withCredentials flag indicates whether the request should be made using credentials such as cookies or authorization headers. The listeners Add listeners for request. The postProcessor is method for changing agent response before than the response is saved in cache and returned in promise.
Returns:
A promise that resolves to the response. The response body will be parsed according to the Content-Type response header's value.
Type
Promise.<{status: number, body: *, params: {method: string, url: string, transformedUrl: string, data: Object.<string, (boolean|number|string)>}, headers: Object.<string, string>, cached: boolean}>

setDefaultHeader(header, value) → {HttpAgent}

Source:
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