@osskit/fetch-enhancers
TypeScript icon, indicating that this package has built-in type declarations

4.5.0 • Public • Published

fetch-enhancers logo

A collection of composable enhancers on top of standard JS FetchAPI.

Bring your own FetchAPI implementation 🙏

Install

yarn add @osskit/fetch-enhancers

Usage

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

Readme

Keywords

none

Package Sidebar

Install

npm i @osskit/fetch-enhancers

Weekly Downloads

7,608

Version

4.5.0

License

none

Unpacked Size

16.9 kB

Total Files

30

Last publish

Collaborators

  • osskit