Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@osskit/fetch-enhancers

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@osskit/fetch-enhancers

A collection of composable enhancers on top of standard js fetch api. Does not include a fetch implementation, you need to bring your owm.

  • 0.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.6K
decreased by-6.09%
Maintainers
1
Weekly downloads
 
Created
Source

fetch-enhancers

A collection of composable enhancers on top of standard js fetch api. Does not include a fetch implementation, you need to bring your owm.

install

yarn add @osskit/fetch-enhancers

usage

import fetch from 'node-fetch'
import {withTimeout,withRetry} from '@osskit/fetch-enhancers'

const fetchWithTimeout = withTimeout(fetch, {
    timeout: {
      requestTimeoutMs: 5000
    }
  }); // *optional* global options 5 seconds timeout

await fetchWithTimeout('http://slow.com/get',{
    enhancers:{
        timeout:{
            requestTimeoutMs: 1000
        }
    }
}) // *optional* per call options 1 second timeout


const fetchWithRetry = withRetry(fetch,{
    retry:{
        minTimeout: 1000, //In MS
        retries: 3,
        factor: 5
    }
}); // *optional* global options (retry is async-retry's options object)

await fetchWithRetry('https://flakey.com/get,{
    retry:{
        minTimeout: 1000, //In MS
        retries: 10,
        factor: 2
    }
}); // *optional* per call options (retry is async-retry's options object)


// compose enhancers

const fetchWithRetryAndTimeout = withRetry(
  withTimeout(fetch, {
    timeout: {
      requestTimeoutMs: 5000
    }
  }),
  {
    retry: {
      minTimeout: 1000, //In MS
      retries: 3,
      factor: 5
    }
  }
);

const fetchWithRetryAndTimeout = withRetry(withTimeout(fetch)); // no global options

// per call options when composing enhancers
await fetchWithRetryAndTimeout('https://slow-and-flakey/get',{
    enhancers:{
        retry:{
            minTimeout: 1000, //In MS
            retries: 3,
            factor: 5
        },
        timeout:{
            requestTimeoutMs: 5000
        }
    }
})

FAQs

Package last updated on 01 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc