Skip to content

Commit 1c8de1a

Browse files
committed
Update Readme
1 parent afabcc5 commit 1c8de1a

File tree

1 file changed

+67
-3
lines changed

1 file changed

+67
-3
lines changed

README.md

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,76 @@
33
[![dependencies Status](https://david-dm.org/flexdinesh/axios-retry-interceptor/status.svg)](https://david-dm.org/flexdinesh/axios-retry-interceptor)
44
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
55

6-
**To be updated...**
6+
Configurable Axios Interceptor to retry failed http calls.
77

8+
## Install
89

9-
## Why? [![start with why](https://img.shields.io/badge/start%20with-why%3F-brightgreen.svg?style=flat)](http://www.ted.com/talks/simon_sinek_how_great_leaders_inspire_action)
10+
```
11+
npm install --save axios-retry-interceptor
12+
```
1013

11-
**To be updated...**
14+
## Usage
15+
16+
Import
17+
```js
18+
import retryInterceptor from 'axios-retry-interceptor';
19+
// or
20+
const retryInterceptor = require('axios-retry-interceptor');
21+
```
22+
23+
Set the interceptor for your axios instance. Voila! ✨
24+
```js
25+
retryInterceptor(axios, {
26+
maxAttempts: 3,
27+
waitTime: 1000
28+
});
29+
30+
```
31+
32+
## API
33+
34+
### retryInterceptor(axiosInstance, options)
35+
36+
- axiosInstance - your axios instance
37+
- options - config for retry interceptor
38+
39+
### Options
40+
41+
#### maxAttempts
42+
43+
Max number of times the interceptor should retry the failed http call.
44+
45+
_Type_: Number
46+
47+
_Default_: 3
48+
49+
_Example_: `maxAttempts: 5`
50+
51+
#### waitTime
52+
53+
Duration between each retry attempt in milliseconds(1s=1000ms).
54+
55+
_Type_: Number
56+
57+
_Default_: 0
58+
59+
_Example_: `waitTime: 3000`
60+
61+
#### statuses
62+
63+
Response statuses for which the interceptor should retry.
64+
65+
Ideally any implementation should retry only 5xx status(server errors) and should not retry 4xx status(client errors). The reason is, if a http call fails with a client error, then the retry call will have the same headers/params and will obviously fail. So **by default all 5xx errors will be retried**. If you want to customize the status for which the retries should be made, use this config.
66+
67+
_Type_: Array
68+
69+
_Default_: []
70+
71+
_Example_: `[500, 501, 401]`
72+
73+
## Author's note
74+
75+
Ideally only idempotent http methods (GET, PUT, DELETE, HEAD, OPTIONS) should be retried on failed http calls. Non-idempotent methods like POST should **NOT** be retried and that's why this library will not permit retry of non-idempotent methods.
1276

1377
## License
1478

0 commit comments

Comments
 (0)