Skip to main content

Class: HttpAgent

@ima/core.HttpAgent

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

Hierarchy

Constructors

constructor

new HttpAgent()

Methods

clearDefaultHeaders

clearDefaultHeaders(): HttpAgent

Clears all configured default headers.

Returns

HttpAgent

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

NameType
Bunknown

Parameters

NameTypeDescription
urlstringThe URL to which the request should be made.
data?UnknownParametersThe 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

NameType
Bunknown

Parameters

NameTypeDescription
urlstringThe URL to which the request should be made.
data?UnknownParametersThe 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

NameTypeDescription
methodstringThe HTTP method used by the request.
urlstringThe URL to which the request is sent.
dataUnknownParametersThe 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

NameType
methodstring
urlstring
dataUnknownParameters

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

NameType
Bunknown

Parameters

NameTypeDescription
urlstringThe URL to which the request should be made.
data?UnknownParametersThe 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

NameType
Bunknown

Parameters

NameTypeDescription
urlstringThe URL to which the request should be made.
data?UnknownParametersThe 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

NameType
Bunknown

Parameters

NameTypeDescription
urlstringThe URL to which the request should be made.
data?UnknownParametersThe 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

NameTypeDescription
headerstringThe name of the header.
valuestringThe header value. To provide multiple values, separate them with commas (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2).

Returns

HttpAgent

This HTTP agent.

Defined in

packages/core/src/http/HttpAgent.ts:204