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

requestretry

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

requestretry

request-retry wrap nodejs request to retry http(s) requests in case of error

  • 3.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
48K
decreased by-80.48%
Maintainers
1
Weekly downloads
 
Created

What is requestretry?

The requestretry npm package is a wrapper around the popular request library that adds automatic retry functionality for failed HTTP requests. It allows you to specify retry strategies, including the number of retries, delay between retries, and conditions under which to retry.

What are requestretry's main functionalities?

Basic HTTP Request with Retry

This feature allows you to make an HTTP GET request with automatic retries. You can specify the maximum number of attempts, the delay between retries, and the retry strategy.

const request = require('requestretry');

request({
  url: 'https://api.example.com/data',
  method: 'GET',
  maxAttempts: 5,   // (default) try 5 times
  retryDelay: 5000, // (default) wait for 5s before trying again
  retryStrategy: request.RetryStrategies.HTTPOrNetworkError // (default) retry on 5xx or network errors
}, function (err, response, body) {
  if (err) {
    console.error('Failed:', err);
  } else {
    console.log('Success:', body);
  }
});

Custom Retry Strategy

This feature allows you to define a custom retry strategy. In this example, the request will be retried if there is an error or if the response status code is 502 (Bad Gateway).

const request = require('requestretry');

function myRetryStrategy(err, response, body) {
  // retry the request if we had an error or if the response was a 'Bad Gateway'
  return err || response.statusCode === 502;
}

request({
  url: 'https://api.example.com/data',
  method: 'GET',
  maxAttempts: 3,
  retryDelay: 3000,
  retryStrategy: myRetryStrategy
}, function (err, response, body) {
  if (err) {
    console.error('Failed:', err);
  } else {
    console.log('Success:', body);
  }
});

POST Request with Retry

This feature demonstrates how to make an HTTP POST request with automatic retries. The request includes a JSON body and will retry up to 4 times with a 2-second delay between attempts.

const request = require('requestretry');

request({
  url: 'https://api.example.com/data',
  method: 'POST',
  json: true,
  body: { key: 'value' },
  maxAttempts: 4,
  retryDelay: 2000,
  retryStrategy: request.RetryStrategies.HTTPOrNetworkError
}, function (err, response, body) {
  if (err) {
    console.error('Failed:', err);
  } else {
    console.log('Success:', body);
  }
});

Other packages similar to requestretry

FAQs

Package last updated on 28 Nov 2018

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