1.0.6 • Published 2 years ago

@aindu/http-client v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@aindu/http-client

An idiomatic and isomorphic HttpClient based on fetch with native support for TypeScript.

Only supports modern browsers and NodeJS >= 18

Installation

npm install @aindu/http-client

Usage

Instancing the client:

This module was thinking like an instantiable HTTP client for that you need to import and create an instance of the client:

import { HttpClient } from "@aindu/http-client";

const restClient = new HttpClient();

This client by default doesn't need any config, but you can set some things in the config to have a better experience.

HttpClient Config

fielddescriptiontypedefault value
timeouttimeout of the request in msnumberinfinite
retriesthe number of retries after the first requestnumber0
basepathA URL used as a base of all the requeststringnull
serializationan object with two fields (input & output Functions) to map the input (body) or output (response) to another naming convention{ input: Function, output: Function }{ input: null, output: null }

|

For instantiating the HttpClient with any config like be:

import { HttpClient } from "@aindu/http-client";

const restClient = new HttpClient({ ... })

Getting some info

restClient.get<{ status: "UP" | "DOWN" }>("http://www.api.com/health-check")

Posting some info

restClient.post<{ userId: string }>("http://www.api.com/users", { name: "Pepe", surname: "Argento" })

HttpClient API

NOTE: All the methods return Promises.

methodurlbodyoptions
get
post
put
delete
patch
makeRequest
1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago