1.3.0 • Published 7 years ago
isomorphic-fetch-improve v1.3.0
isomorphic-fetch-improve
Improvements over isomorphic-fetch.
Installation
npm i isomorphic-fetch-improve -SUsage
const fetch = require('isomorphic-fetch-improve')
const url = 'http://localhost:3000/test'
fetch(url, {
timeout: 1000 * 30, // 30s
retryDelay: 1000, // 1s
retryMaxCount: 10, // total 11 times request
cancelableTaskName: 'task1',
auth: {user: 'admin', password: 'secret'}, // basic auth
method: 'get', // to upper case
// forceMethod: 'PATCH', // case sensitive
// ...
}).catch(err => {
if (err.message == 'timeout') {
// Request timeout
} else if (err.message == 'cancel') {
// This request was cancelled due to there is a new request
} else {
// Other
}
})
// Send a request by the same task name again
fetch(url || null, {
cancelableTaskName: 'task1',
})Additional options
timeoutDefault:0Set timeout.retryMaxCountDefault:InfinitySet retry max count, when an error occurred, such as refresh, lock screen.retryDelayDefault:0Set delay milliseconds when retry.cancelableTaskNameDefault:nullSet the task name, to avoid the response data is replaced by old request in the response period.authDefault:nullSetuserandpasswordfor basic authentication (Apply to relative paths).forceMethodDefault:nullSet an original value to the request method.
License
MIT