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

@0xbeejs/fetch

Package Overview
Dependencies
Maintainers
0
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0xbeejs/fetch

Provides an interface for fetching resources, base on [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).

  • 0.0.2
  • latest
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

@0xbeejs/fetch

Provides an interface for fetching resources, base on Fetch API.

Fetures

  • Supports Node.js and browsers
  • Supports specifying a timeout.
  • Supports specifying a proxy.

Installation

$ yarn add @0xbeejs/fetch

Usage

fetch
import fetch from "@0xbeejs/fetch";


function fetchWithTimeout() {
    const timeout = 15000; // 15s
    return fetch("http://www.google.com", {
        // optional
        proxyUrl: "http://127.0.0.1:7890",
    }, timeout)
}


const rsp = await fetchWithTimeout()

console.log(await rsp.text())

faithfulRequest

Execute a specific asynchronous action until timeout, supporting automatic retries, specifying the number of retries, and retry conditions.

import fetch from "@0xbeejs/fetch";


function fetchWithTimeout() {
    const timeout = 15000; // 15s
    return fetch("http://www.google.com", {
        // optional
        proxyUrl: "http://127.0.0.1:7890",
    }, timeout)
}

const resp = await faithfulRequest({
    req: () => fetchWithTimeout(),
    id: "get_google_homepage",
    // Optional. The assertion is true, and it will continue retrying until the maximum number of attempts is reached.
    maxRetries: -1, // -1: no limit,
    // Optional
    assert: (ex) => ex.name === "timeout" // 'true' will retry util reach the 'maxRetries'
    // Optional, how long to wait before starting the next request
})

Keywords

FAQs

Package last updated on 25 Dec 2024

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