Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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

Awesome Lists containing this project

README

        


fetch-enhancers logo


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 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,
},
);
```