🚀 Big News:Socket Has Acquired Secure Annex.Learn More →
Socket
Book a DemoSign in
Socket

fetch-retry-helper

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fetch-retry-helper

A utility to retry HTTP requests with exponential backoff.

latest
npmnpm
Version
2.0.0
Version published
Maintainers
2
Created
Source

retry-fetch is a simple Node.js utility that performs a fetch request with an exponential backoff retry mechanism. This module is useful when you want to ensure your fetch requests are resilient to transient errors such as network issues or temporary server unavailability.

Installation To install retry-fetch, you need to have Node.js and npm installed. Then, run the following

npm install retry-fetch

const retryFetch = require('retry-fetch');

const url = 'https://api.example.com/data'; const options = { method: 'GET', headers: { 'Content-Type': 'application/json', }, };

retryFetch(url, options, 3, 1000) .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error('Fetch error:', error));

API retryFetch(url, options = {}, retries = 3, delay = 1000) Performs a fetch request with an exponential backoff retry mechanism.

Parameters url string - The URL to fetch. options object (optional) - The options for the fetch request. This is passed directly to fetch. retries number (optional, default: 3) - The number of times to retry the fetch request before failing. delay number (optional, default: 1000) - The initial delay in milliseconds before the first retry. The delay will double with each retry. Returns Promise - The fetch response.

Example : const retryFetch = require('retry-fetch');

const url = 'https://api.example.com/data';

retryFetch(url, {}, 5, 500) .then(response => { if (!response.ok) { throw new Error(HTTP error! status: ${response.status}); } return response.json(); }) .then(data => console.log(data)) .catch(error => console.error('Fetch error:', error));

Keywords

fetch

FAQs

Package last updated on 01 Jul 2025

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