Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/osskit/fetch-enhancers
A suite of HoCs to enrich your Fetch calls
https://github.com/osskit/fetch-enhancers
enrichment fetch fetch-api hoc nodejs
Last synced: 9 days ago
JSON representation
A suite of HoCs to enrich your Fetch calls
- Host: GitHub
- URL: https://github.com/osskit/fetch-enhancers
- Owner: osskit
- License: mit
- Created: 2021-07-14T13:53:23.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-08T17:38:28.000Z (16 days ago)
- Last Synced: 2024-12-12T01:06:40.345Z (13 days ago)
- Topics: enrichment, fetch, fetch-api, hoc, nodejs
- Language: TypeScript
- Homepage:
- Size: 365 KB
- Stars: 1
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
A collection of composable enhancers on top of standard JS FetchAPI.Bring your own FetchAPI implementation :pray:
# Install
```shell
yarn add @osskit/fetch-enhancers
```# Usage
```js
import { withTimeout, withRetry } from '@osskit/fetch-enhancers';const fetchWithTimeout = withTimeout(fetch, {
requestTimeoutMs: 5000,
}); // *optional* global options 5 seconds timeoutconst 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,
},
);
```