A simple isomorphic wrapper around fetch with retries and error handling
This package is a simple wrapper around isomorphic-fetch that adds some utilities, such as retries, error handling, as well as doing some automatic conversions of data (like building the query string from an object).
npm install fetch-plus-plus
const fetch = require('fetch-plus-plus').default
fetch('https://some-json-api.com', {
headers: {
'Authorization': 'Bearer <some-bearer>',
'Content-Type': 'application/json'
},
insecure: true,
method: 'POST',
queryString: { api: 'some-private-api' },
retries: 3
}).then(function (jsonResponse) {
// jsonResponse is a JSON object
})
Returns a Promise which will be resolved to the response of the request.
Type: string
The URL to request.
Type: object
It uses fetch default options, extending it with the following options:
Type: boolean
Default: false
Returns the body instead of throwing if the request failed
Type: boolean
Default: false
Allows insecure requests (such as self-signed certificates) instead of rejecting them
Type: object
Default: {}
The object that will be converted to a query string and append to the URL
Type: number
Default: 0
The max number of retries to attempt if the request fails.