Socket
Socket
Sign inDemoInstall

timed-fetch

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

timed-fetch

API fetch using a time-boxed request limit


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

timed-fetch

Description

Isomorphic fetch wrapper that allows the setting of a max wait-time for a response, if the wait-time is exceeded a 408 Request Timeout HTTP Status Code will be sent back. This allows developers to handle excessivly long API calls without making the user wait, whether the issue stems from a bad internet connection, or a slow backend service.

Code Example

import timedFetch from 'timed-fetch'

const fetchDataWith4SecondLimit = async () => {
  const options = {
    timeout: 4, // wait 4 seconds max for fetch response.
    method: "GET",
  }

  try {
    const response = await timedFetch("https://example.com/api", options)
    const json = response.json()

    return json
  } catch (err) {
    return new Error(err.message)
  }
}

FAQs

Package last updated on 30 Jan 2023

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