retryable-request
v1.0.11
Published
Small lib helps sending retryable requests on top of axios
Downloads
3
Readme
retryable-request
Sending retryable requests easily
Table of Contents
- [Features](#features)
- [Installing](#installing)
- [Example](#example)
- [Credits](#credits)
- [License](#license)
Features
- Send normal request using sendRequest function
- Creating retryable request using createRetryableRequest function
- Send retryable request using sendRetryable request function
- Alternatively you can perform the previous functionality using RetryableRequest class instead.
- Everything is promise based and compaitable with axios http client
Installing
Using npm:
$ npm install retryable-request
Using yarn:
$ yarn add retryable-request
Example
const { createRetryableRequest } = require("retryable-request");
const request = createRetryableRequest({
requestOptions: {
url: "https://jsonplaceholder.typicode.com/todos",
},
retryOptions: {
retries: 3,
},
retryCB: (e, currentAttempt) =>
console.log(`${e.message} - currentAttempt: ${currentAttempt}`),
});
request()
.then((data) => console.log(data.data))
.catch((e) => console.log(e.message));
// using RetryableRequest class which supports axios interceptors and have default ones
const {RetryableRequest} = require("retryable-request");
const client = RetryableRequest.instance({ defaultInterceptors: true });
// normal request
client.sendRequest({
url:"https://jsonplaceholder.typicode.com/todos",
}).then(console.log).catch(console.log);
// retryable request
client.sendRetryableRequest({
requestOptions: {
url: "https://jsonplaceholder.typicode.com/todos",
},
retryOptions: {
retries: 3,
},
retryCB: (e, currentAttempt) =>
console.log(e,currentAttempt),
}).then(console.log).catch(console.log);
Credits
- Abd Allah Zidan
License
- MIT