{"library":"requestretry","title":"HTTP(S) Request Retry","description":"request-retry is a Node.js library designed to automatically re-attempt HTTP(S) requests that fail due to transient network errors or specific HTTP status codes like 5xx and 429 (Too Many Requests). It functions as a wrapper, providing a drop-in replacement API for the underlying HTTP client, but with added configurable retry logic including `maxAttempts`, `retryDelay`, and a customizable `retryStrategy`. The current stable version, 8.0.0, marks a significant shift, migrating its core dependency from the unmaintained `request` library to the more actively developed `postman-request` fork, addressing security concerns and ensuring continued functionality. This package is crucial for building robust network clients that can gracefully handle temporary service disruptions, simplifying the implementation of resilient communication patterns by abstracting away common retry mechanisms.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install requestretry"],"cli":null},"imports":["const request = require('requestretry');","const request = require('requestretry');\nconst strategy = request.RetryStrategies.HTTPOrNetworkError;","const request = require('requestretry');\nrequest({ /* options */ }).then(/* ... */);"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"// First, ensure you have the necessary peer dependency installed:\n// npm install requestretry postman-request\n\nconst request = require('requestretry');\n\nasync function makeRetriedRequest() {\n  console.log('Initiating retriable HTTP request...');\n  try {\n    const response = await request({\n      url: 'https://httpstat.us/503', // An endpoint that reliably returns a 503 (Service Unavailable)\n      json: true, // Parse response body as JSON\n      maxAttempts: 3,   // Configure up to 3 attempts\n      retryDelay: 1000,  // Wait 1 second between retries\n      retryStrategy: request.RetryStrategies.HTTPOrNetworkError, // Retry on 5xx status codes or network errors\n      fullResponse: true // Resolve the promise with the full response object, including headers and status\n    });\n\n    console.log(`\\nRequest successfully completed after ${response.attempts} attempts.`);\n    console.log(`HTTP Status Code: ${response.statusCode}`);\n    console.log(`Response Body: ${JSON.stringify(response.body, null, 2)}`);\n  } catch (error) {\n    console.error(`\\nRequest failed after all attempts. Error: ${error.message}`);\n    if (error.attempts) {\n      console.error(`Total attempts made: ${error.attempts}`);\n    }\n  }\n}\n\nmakeRetriedRequest();","lang":"javascript","description":"Demonstrates a basic promise-based HTTP GET request using request-retry, configured to retry on 5xx errors or network issues with a delay.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}