A collection of composable enhancers on top of standard JS FetchAPI.
Bring your own FetchAPI implementation 🙏
yarn add @osskit/fetch-enhancers
import { withTimeout, withRetry } from '@osskit/fetch-enhancers';
const fetchWithTimeout = withTimeout(fetch, {
requestTimeoutMs: 5000,
}); // *optional* global options 5 seconds timeout
const fetchWithRetry = withRetry(fetch, {
retries: 3,
minTimeout: 1000, // In ms
maxTimeout: 5000, // In ms
factor: 5,
randomize: false,
}); // *optional* global options object is async-retry's options object
// Compose enhancers:
const fetchWithRetryAndTimeout = withRetry(
withTimeout(fetch, {
requestTimeoutMs: 5000,
}),
{
minTimeout: 1000, // In ms
retries: 3,
factor: 5,
},
);