phin-retry
The ultra-lightweight Node.js HTTP client.
This is a wrapper around Phin that adds support for retry & looks like request-promise.
Install
npm install phin-retry
Usage
const request = ; // should be used in async contextconst response = await request; await request; // custom retry, error & delay strategyconst response = await request;
- It supports get, post, put, delete, patch HTTP methods.
- By default, this library will retry once on failure (StatusCode >= 500 & network errors) with a delay of 100 or 1000 milliseconds. Override this behavior with custom retry strategy function.
- Responses with status codes < 200 & >= 300 are thrown as errors. Override this behavior with custom error strategy function.
- All options from phin are supported. Refer Phin for more usage examples.
- Access underlying phin library through
request.phin
.
API
Defaults
Access default options through request.defaults
.
Option | Type | Description |
---|---|---|
retry |
number | max no of times to retry (1) |
delay |
number | delay between retries (100ms) |
networkErrorDelay |
number | delay for network errors (1000ms) |
retryStrategy |
function | default retry strategy function |
delayStrategy |
function | default delay strategy function |
errorStrategy |
function | default error strategy function |
Options
It supports all options from phin, refer Phin for more details.
Method | Type | Description |
---|---|---|
url |
string | request url |
qs |
object | query parameters |
auth |
object | authentication object |
headers |
object | headers object |
retry |
number | max no of times to retry |
delay |
number | delay between retries |
body |
any | equivalent to data in phin |
fullResponse |
boolean | returns full phin response |
retryStrategy |
function | custom retry strategy function |
delayStrategy |
function | custom delay strategy function |
errorStrategy |
function | custom error strategy function |