Skip to main content
Module

x/httpclient/HttpClient.ts>HttpClient

Fetch based modern http client, supports node, web, deno!
Latest
class HttpClient
import { HttpClient } from "https://deno.land/x/httpclient@0.0.1/HttpClient.ts";

Fetch based modern and customizable http client

Constructors

new
private
HttpClient(middlewares: IMiddleware<Ctx>[])

Type Parameters

Ctx extends CtxBase

Properties

private
optional
_baseURL: URL
private
_defaultExecutor: Executor<Ctx>
private
_dHeaders: _Headers
private
_middlewares: IMiddlewareFn<Ctx>[]
storage: Record<string | symbol | number, any>

Methods

baseURL(url: string | URL): this

Set baseURL of client

createContext(path: string, init?: OptionsInit<Ctx>): Ctx

Create a new request context

delete(path: string, options?: OptionsInit<Ctx>)

DELETE request

get<R>(path: string, options?: OptionsInit<Ctx>)

GET request

headers(...args: [_HeadersInit] | [string, string]): this

Set Headers

isContext(val: any): val is Ctx

Check if val is context

patch(path: string, options?: OptionsInit<Ctx>)

PATCH request

post<R>(path: string, options?: OptionsInit<Ctx>)

POST request

put(path: string, options?: OptionsInit<Ctx>)

PUT request

request<R>(
path: string,
method: HttpMethod,
init?: OptionsInit<Ctx>,
): HttpClientThenableResponse<R, Ctx>

Use wrapper methods (this.get or this.post ...)

use(...middlwares: IMiddleware<Ctx>[]): this

Dynamically add middlware

Static Methods

[CREATE_SYMBOL]<C extends CtxBase>(middlewares: IMiddleware<C>[]): HttpClient<C>