Class: HttpAgentImpl
Defined in: packages/core/src/http/HttpAgentImpl.ts:27
Implementation of the HttpAgent interface with internal caching of completed and ongoing HTTP requests and cookie storage.
Extends
Constructors
new HttpAgentImpl()
new HttpAgentImpl(
proxy
,cache
,cookie
,config
,Helper
):HttpAgentImpl
Defined in: packages/core/src/http/HttpAgentImpl.ts:69
Initializes the HTTP handler.
Parameters
proxy
The low-level HTTP proxy for sending the HTTP requests.
cache
Cache
<HttpAgentResponse
<unknown
>>
Cache to use for caching ongoing and completed requests.
cookie
The cookie storage to use internally.
config
HttpAgentImplConfig
Configuration of the HTTP handler for the current application environment, specifying the various default request option values and cache option values.
Helper
__module
The IMA.js helper methods.
Returns
Examples
http
.get('url', { data: data }, {
ttl: 2000,
repeatRequest: 1,
withCredentials: true,
timeout: 2000,
accept: 'application/json',
language: 'en'
})
.then((response) => {
//resolve
}
.catch((error) => {
//catch
});
http
.setDefaultHeader('Accept-Language', 'en')
.clearDefaultHeaders();
Overrides
Properties
_cache
protected
_cache:Cache
<HttpAgentResponse
<unknown
>>
Defined in: packages/core/src/http/HttpAgentImpl.ts:29
_cacheOptions
protected
_cacheOptions:HttpAgentImplCacheOptions
Defined in: packages/core/src/http/HttpAgentImpl.ts:31
_cookie
protected
_cookie:CookieStorage
Defined in: packages/core/src/http/HttpAgentImpl.ts:30
_defaultRequestOptions
protected
_defaultRequestOptions:HttpAgentRequestOptions
Defined in: packages/core/src/http/HttpAgentImpl.ts:32
_Helper
protected
_Helper:__module
Defined in: packages/core/src/http/HttpAgentImpl.ts:33
_internalCacheOfPromises
protected
_internalCacheOfPromises:Map
<any
,any
>
Defined in: packages/core/src/http/HttpAgentImpl.ts:34
_proxy
protected
_proxy:HttpProxy
Defined in: packages/core/src/http/HttpAgentImpl.ts:28
Methods
_cleanResponse()
_cleanResponse<
B
>(response
):HttpAgentResponse
<B
>
Defined in: packages/core/src/http/HttpAgentImpl.ts:540
Cleans cache response from data (abort controller, postProcessors), that cannot be persisted, before saving the data to the cache.
Type Parameters
• B
Parameters
response
Returns
_clone()
_clone<
V
>(value
):V
Defined in: packages/core/src/http/HttpAgentImpl.ts:221
Attempts to clone the provided value, if possible. Values that cannot be cloned (e.g. promises) will be simply returned.
Type Parameters
• V
Parameters
value
V
The value to clone.
Returns
V
The created clone, or the provided value if the value cannot be cloned.
_getCachedData()
_getCachedData<
B
>(method
,url
,data
?):null
|Promise
<HttpAgentResponse
<B
>>
Defined in: packages/core/src/http/HttpAgentImpl.ts:278
Tests whether an ongoing or completed HTTP request for the specified URL and data is present in the internal cache and, if it is, the method returns a promise that resolves to the response body parsed as JSON.
The method returns null
if no such request is present in the
cache.
Type Parameters
• B
Parameters
method
string
The HTTP method used by the request.
url
string
The URL to which the request was made.
data?
The data sent to the server with the request.
Returns
null
| Promise
<HttpAgentResponse
<B
>>
A promise that will resolve to the
server response with the body parsed as JSON, or null
if
no such request is present in the cache.
_getCacheKeySuffix()
_getCacheKeySuffix(
method
,url
,data
?):string
Defined in: packages/core/src/http/HttpAgentImpl.ts:478
Generates cache key suffix for an HTTP request to the specified URL with the specified data.
Parameters
method
string
The HTTP method used by the request.
url
string
The URL to which the request is sent.
data?
The data sent with the request.
Returns
string
The suffix of a cache key to use for a request to the specified URL, carrying the specified data.
_prepareOptions()
_prepareOptions(
options
,url
):HttpAgentRequestOptions
Defined in: packages/core/src/http/HttpAgentImpl.ts:435
Prepares the provided request options object by filling in missing options with default values and adding extra options used internally.
Parameters
options
Partial
<HttpAgentRequestOptions
> = {}
Optional request options.
url
string
Returns
Request options with set filled-in default values for missing fields, and extra options used internally.
_proxyRejected()
_proxyRejected<
B
>(error
):Promise
<HttpAgentResponse
<B
>>
Defined in: packages/core/src/http/HttpAgentImpl.ts:398
Handles rejection of the HTTP request by the HTTP proxy. The method tests whether there are any remaining tries for the request, and if there are any, it attempts re-send the request.
The method rejects the internal request promise if there are no tries left.
Type Parameters
• B
Parameters
error
GenericError
<HttpProxyErrorParams
>
The error provided by the HttpProxy, carrying the error parameters, such as the request url, data, method, options and other useful data.
Returns
Promise
<HttpAgentResponse
<B
>>
A promise that will either resolve to a server's response (with the body parsed as JSON) if there are any tries left and the re-tried request succeeds, or rejects with an error containing details of the cause of the request's failure.
_proxyResolved()
_proxyResolved<
B
>(response
):HttpAgentResponse
<B
>
Defined in: packages/core/src/http/HttpAgentImpl.ts:343
Handles successful completion of an HTTP request by the HTTP proxy.
The method also updates the internal cookie storage with the cookies received from the server.
Type Parameters
• B
Parameters
response
Server response.
Returns
The post-processed server response.
_request()
_request<
B
>(method
,url
,data
,options
):Promise
<HttpAgentResponse
<B
>>
Defined in: packages/core/src/http/HttpAgentImpl.ts:314
Sends a new HTTP request using the specified method to the specified url. The request will carry the provided data as query parameters if the HTTP method is GET, but the data will be sent as request body for any other request method.
Type Parameters
• B
Parameters
method
string
HTTP method to use.
url
string
The URL to which the request is sent.
data
The data sent with the request.
undefined
| UnknownParameters
options
Optional request options.
Returns
Promise
<HttpAgentResponse
<B
>>
A promise that resolves to the response with the body parsed as JSON.
_requestWithCheckCache()
_requestWithCheckCache<
B
>(method
,url
,data
?,options
?):Promise
<HttpAgentResponse
<B
>>
Defined in: packages/core/src/http/HttpAgentImpl.ts:243
Check cache and if data isn’t available then make real request.
Type Parameters
• B
Parameters
method
string
The HTTP method to use.
url
string
The URL to which the request should be sent.
data?
The data to send with the request.
options?
Partial
<HttpAgentRequestOptions
>
Optional request options.
Returns
Promise
<HttpAgentResponse
<B
>>
A promise that resolves to the response with body parsed as JSON.
_saveAgentResponseToCache()
_saveAgentResponseToCache<
B
>(agentResponse
):void
Defined in: packages/core/src/http/HttpAgentImpl.ts:522
Saves the server response to the cache to be used as the result of the next request of the same properties.
Type Parameters
• B
Parameters
agentResponse
The response of the server.
Returns
void
_setCookiesFromResponse()
_setCookiesFromResponse<
B
>(agentResponse
):void
Defined in: packages/core/src/http/HttpAgentImpl.ts:501
Sets all cookies from the Set-Cookie
response header to the
cookie storage.
Type Parameters
• B
Parameters
agentResponse
The response of the server.
Returns
void
clearDefaultHeaders()
clearDefaultHeaders():
this
Defined in: packages/core/src/http/HttpAgentImpl.ts:207
Clears all configured default headers.
Returns
this
This HTTP agent.
Overrides
delete()
delete<
B
>(url
,data
?,options
?):Promise
<HttpAgentResponse
<B
>>
Defined in: packages/core/src/http/HttpAgentImpl.ts:164
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.
Type Parameters
• B = unknown
Parameters
url
string
The URL to which the request should be made.
data?
The data to send to the server as the request body.
options?
Partial
<HttpAgentRequestOptions
>
Optional request options.
Returns
Promise
<HttpAgentResponse
<B
>>
A promise that resolves to the response.
Overrides
get()
get<
B
>(url
,data
?,options
?):Promise
<HttpAgentResponse
<B
>>
Defined in: packages/core/src/http/HttpAgentImpl.ts:105
Sends an HTTP GET request to the specified URL, sending the provided data as query parameters.
Type Parameters
• B = unknown
Parameters
url
string
The URL to which the request should be made.
data?
The data to send to the server as query parameters.
options?
Partial
<HttpAgentRequestOptions
>
Optional request options.
Returns
Promise
<HttpAgentResponse
<B
>>
A promise that resolves to the response.
Overrides
getCacheKey()
getCacheKey(
method
,url
,data
?):string
Defined in: packages/core/src/http/HttpAgentImpl.ts:180
Generates a cache key to use for identifying a request to the specified URL using the specified HTTP method, submitting the provided data.
Parameters
method
string
The HTTP method used by the request.
url
string
The URL to which the request is sent.
data?
The data associated with the request. These can be either the query parameters or request body data.
Returns
string
The key to use for identifying such a request in the cache.
Overrides
invalidateCache()
invalidateCache(
method
,url
,data
?):void
Defined in: packages/core/src/http/HttpAgentImpl.ts:189
Method invalidate cache for given params
Parameters
method
string
url
string
data?
Returns
void
Overrides
patch()
patch<
B
>(url
,data
?,options
?):Promise
<HttpAgentResponse
<B
>>
Defined in: packages/core/src/http/HttpAgentImpl.ts:148
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.
Type Parameters
• B = unknown
Parameters
url
string
The URL to which the request should be made.
data?
The data to send to the server as the request body.
options?
Partial
<HttpAgentRequestOptions
>
Optional request options.
Returns
Promise
<HttpAgentResponse
<B
>>
A promise that resolves to the response.
Overrides
post()
post<
B
>(url
,data
?,options
?):Promise
<HttpAgentResponse
<B
>>
Defined in: packages/core/src/http/HttpAgentImpl.ts:116
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.
Type Parameters
• B = unknown
Parameters
url
string
The URL to which the request should be made.
data?
The data to send to the server as the request body.
options?
Partial
<HttpAgentRequestOptions
>
Optional request options.
Returns
Promise
<HttpAgentResponse
<B
>>
A promise that resolves to the response.
Overrides
put()
put<
B
>(url
,data
?,options
?):Promise
<HttpAgentResponse
<B
>>
Defined in: packages/core/src/http/HttpAgentImpl.ts:132
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.
Type Parameters
• B = unknown
Parameters
url
string
The URL to which the request should be made.
data?
The data to send to the server as the request body.
options?
Partial
<HttpAgentRequestOptions
>
Optional request options.
Returns
Promise
<HttpAgentResponse
<B
>>
A promise that resolves to the response.
Overrides
setDefaultHeader()
setDefaultHeader(
header
,value
):this
Defined in: packages/core/src/http/HttpAgentImpl.ts:198
Sets the specified header to be sent with every subsequent HTTP request, unless explicitly overridden by request options.
Parameters
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
This HTTP agent.