A library that can handle your all kind of request .It make use of Axios and node-fetch internally to reduce your dependency on third party libraries.A single place to handle all your request. It also notes the time in which your api sends the response,keep notes of all request and response and also has retrying feature,means if api fails,it will retry certain number of times (default 5)
Github link:- https://github.com/shubham262/axioslibrary
Package link:- https://www.npmjs.com/package/axioslibrary
-
Uses Axios and Node-fetch internally to make request and reduce your dependency on library directly.
-
User can either use Axios or Node-fetch.
-
Logs the incoming request with its response and Keep all the information of the request
-
Has the timing feature, notes the time taken by the api to respond to the request.
-
Has the retrying feature, if the request fails due to certain reasons and response has status code like [408, 500, 502, 503, 504, 522, 524],the library will make request again and again ,by default 5 times and return the final result. Users can also set no of retries.
-
Has timeout feature, which automatically cancels the request ,if the api took more than 5seconds.This timeout can also be defined by the users.
- npm i axioslibrary
- const {bot}=require("axioslibrary")
- import {bot} from “axioslibrary“
- const config={
method:"get",
baseURL:"https://httpbin.org",
url:"/get",
data:{ title: 'foo',body: 'bar',userId: 1,},
params: {
ID: 12345,
},
retry:true,
retries:5,
usage:"axios",
timeout:5000
}
- async function makeRequest() {
try {
const response = await bot(config);
console.log(response);
} catch (error) {
console.error(error);
}
}
- bot(config).then((data)=>{
console.log(data)
}).catch((errror)=>console.log(error))