1.8.3 • Published 1 year ago
myfetchapi v1.8.3
myfetchapi
A simple fetch wrapper with concurrency control and retry functionality that works on both nodejs, browser and edge environments.
Installation
You can install this package via npm:
npm install myfetchapi
yarn add myfetchapi
bun add myfetchapiUsage
const { myFetch, SET_MAX_CONCURRENT_REQUESTS } = require("myfetchapi");
// Set maximum concurrent requests. default is 20
SET_MAX_CONCURRENT_REQUESTS(20);
// Make a request
myFetch(
"https://example.com/api/data",
{
method: "GET"
maxRetries: 5 /* default is 3. To disable retries, set it to `null` or `0` */,
}
)
.then((response) => console.log(response))
.catch((error) => console.error(error));API
myFetch
The main function to make HTTP requests.
- Parameters:
input: RequestInfo - The URL or Request object.init(optional): RequestInit - The request Options for the HTTP(S) request- Additional options to
init.timeout(optional): number - Request timeout in milliseconds.throwHttpError(optional): boolean - Set this tofalseif you don't want to throw an error when http status is not ok. Default:true.waitForBodyUsed(optional): boolean - Only remove the request from the concurrent request queue after the response body has been fully consumed. This is useful when you need to ensure that the connection is kept alive until the body is read. Default:false.useNodeFetch(optional): boolean - This option is choosen automatically according to the environment it is running on. Set totrueto use Node.js Options, e.g agents, and iffalseit uses the environment's defaultfetchimplementation.maxRetries(optional): number - How many times a request will retry if it failed. Default is 1.retryCb(optional): function - Callback function that is called when the HTTP(S) request is retrying.- Parameters:
err: Error object.count: Retry count.max: Max retry count.
- Parameters:
retryCondition(optional): function - Function to override and set your own condition for retrying.- Parameters:
response: HTTP(S) Response object.
- Returns: boolean | Promise
- Parameters:
- Additional options to
- Returns: Promise
SET_MAX_CONCURRENT_REQUESTS
Function to set the maximum number of concurrent requests.
- Parameters:
max: number - The maximum number of concurrent requests.
License
This project is licensed under the MIT License
1.8.2
1 year ago
1.8.1
1 year ago
1.8.0
1 year ago
1.7.9
1 year ago
1.7.8
1 year ago
1.8.3
1 year ago
1.7.3
2 years ago
1.7.2
2 years ago
1.7.1
2 years ago
1.7.0
2 years ago
1.7.7
2 years ago
1.7.6
2 years ago
1.7.5
2 years ago
1.7.4
2 years ago
1.6.0
2 years ago
1.5.0
2 years ago
1.4.0
2 years ago
1.2.0
2 years ago
1.3.0
2 years ago
1.1.0
2 years ago
1.0.0
2 years ago