HttpClient

Base class in Coolio http package, which allows to perform API calls.

Type parameters

T

Common body shape defined by bodyParser passed in HttpClientConfig.

Hierarchy

  • HttpClient

Index

Constructors

Methods

Constructors

constructor

+ new HttpClient(config: HttpClientConfig‹T›): HttpClient

Parameters:

Name

Type

config

Returns: HttpClient

Methods

addInterceptor

addInterceptor(interceptor: HttpInterceptor): this

Adds an interceptor to the client. Interceptor can be written either as class or as a function, which may mutate request options and post-process response from server. Multiple interceptors can be added to a single HttpClient. They can perform as:

  • cache

  • error handler

  • authorizer

  • logger

  • auto-retry

  • redirection handler

Parameters:

Name

Type

Description

interceptor

Interceptor that will process every request/response in this HttpClient.

Returns: this

delete

delete<Body>(uri: string, options?: HttpOptions): Promise‹HttpResponse‹Body››

Performs a DELETE request.

Type parameters:

Body: T

Parameters:

Name

Type

Description

uri

string

Address of HTTP endpoint

options?

Additional HttpOptions passed with request

Returns: Promise‹HttpResponse‹Body››

get

get<Body>(uri: string, options?: HttpOptions): Promise‹HttpResponse‹Body››

Performs a GET request.

Type parameters:

Body: T

Parameters:

Name

Type

Description

uri

string

Address of HTTP endpoint

options?

Additional HttpOptions passed with request

Returns: Promise‹HttpResponse‹Body››

patch

patch<Body>(uri: string, options?: HttpOptions): Promise‹HttpResponse‹Body››

Performs a PATCH request.

Type parameters:

Body: T

Parameters:

Name

Type

Description

uri

string

Address of HTTP endpoint

options?

Additional HttpOptions passed with request

Returns: Promise‹HttpResponse‹Body››

post

post<Body>(uri: string, options?: HttpOptions): Promise‹HttpResponse‹Body››

Performs a POST request.

Type parameters:

Body: T

Parameters:

Name

Type

Description

uri

string

Address of HTTP endpoint

options?

Additional HttpOptions passed with request

Returns: Promise‹HttpResponse‹Body››

put

put<Body>(uri: string, options?: HttpOptions): Promise‹HttpResponse‹Body››

Performs a PUT request.

Type parameters:

Body: T

Parameters:

Name

Type

Description

uri

string

Address of HTTP endpoint

options?

Additional HttpOptions passed with request

Returns: Promise‹HttpResponse‹Body››

remove

remove<Body>(uri: string, options?: HttpOptions): Promise‹HttpResponse‹any››

Performs a DELETE request.

deprecated Use delete instead of remove, since it matches HTTP request method.

Type parameters:

Body: T

Parameters:

Name

Type

Description

uri

string

Address of HTTP endpoint

options?

Additional HttpOptions passed with request

Returns: Promise‹HttpResponse‹any››

request

request<Body>(url: string, options: HttpRequestOptions): Promise‹HttpResponse‹Body››

Type parameters:

Body: T

Parameters:

Name

Type

url

string

options

Returns: Promise‹HttpResponse‹Body››

Last updated