Class: HttpAgent
@ima/core.HttpAgent
The HttpAgent defines unifying API for sending HTTP requests at both client-side and server-side.
Hierarchy
HttpAgent
Constructors
constructor
• new HttpAgent()
Methods
clearDefaultHeaders
▸ clearDefaultHeaders(): HttpAgent
Clears all configured default headers.
Returns
This HTTP agent.
Defined in
packages/core/src/http/HttpAgent.ts:213
delete
▸ delete<B
>(url
, data?
, options?
): Promise
<HttpAgentResponse
<B
>>
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
Name | Type |
---|---|
B | unknown |
Parameters
Name | Type | Description |
---|---|---|
url | string | The URL to which the request should be made. |
data? | UnknownParameters | 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.
Defined in
packages/core/src/http/HttpAgent.ts:163
get
▸ get<B
>(url
, data?
, options?
): Promise
<HttpAgentResponse
<B
>>
Sends an HTTP GET request to the specified URL, sending the provided data as query parameters.
Type parameters
Name | Type |
---|---|
B | unknown |
Parameters
Name | Type | Description |
---|---|---|
url | string | The URL to which the request should be made. |
data? | UnknownParameters | 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.
Defined in
packages/core/src/http/HttpAgent.ts:79
getCacheKey
▸ getCacheKey(method
, url
, data
): string
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 | UnknownParameters | 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.
Defined in
packages/core/src/http/HttpAgent.ts:183
invalidateCache
▸ invalidateCache(method
, url
, data
): void
Method invalidate cache for given params
Parameters
Name | Type |
---|---|
method | string |
url | string |
data | UnknownParameters |
Returns
void
Defined in
packages/core/src/http/HttpAgent.ts:190
patch
▸ patch<B
>(url
, data?
, options?
): Promise
<HttpAgentResponse
<B
>>
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
Name | Type |
---|---|
B | unknown |
Parameters
Name | Type | Description |
---|---|---|
url | string | The URL to which the request should be made. |
data? | UnknownParameters | 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.
Defined in
packages/core/src/http/HttpAgent.ts:142
post
▸ post<B
>(url
, data?
, options?
): Promise
<HttpAgentResponse
<B
>>
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
Name | Type |
---|---|
B | unknown |
Parameters
Name | Type | Description |
---|---|---|
url | string | The URL to which the request should be made. |
data? | UnknownParameters | 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.
Defined in
packages/core/src/http/HttpAgent.ts:100
put
▸ put<B
>(url
, data?
, options?
): Promise
<HttpAgentResponse
<B
>>
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
Name | Type |
---|---|
B | unknown |
Parameters
Name | Type | Description |
---|---|---|
url | string | The URL to which the request should be made. |
data? | UnknownParameters | 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.
Defined in
packages/core/src/http/HttpAgent.ts:121
setDefaultHeader
▸ setDefaultHeader(header
, value
): HttpAgent
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.