{"library":"retry-axios","title":"Axios Request Retries","description":"retry-axios is a library designed to automatically retry failed HTTP requests made using the Axios client library. It operates as an Axios interceptor, providing built-in exponential backoff and extensive configuration options for retry logic, including HTTP methods, status codes, retry delays, and jitter strategies. The current stable version is 4.0.3, released in April 2026. The package demonstrates a consistent release cadence, with major versions aligning with significant Node.js LTS updates. Key differentiators include its deep integration with Axios interceptors, allowing for global or instance-specific retry policies, and its flexible backoff algorithms (exponential, static, linear) to prevent thundering herd problems, making it suitable for robust client-side network operations in both Node.js and browser environments.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install retry-axios"],"cli":null},"imports":["import * as rax from 'retry-axios';","import { attach } from 'retry-axios';","const rax = require('retry-axios');","import { AxiosRequestConfig } from 'axios';\nimport { RaxConfig } from 'retry-axios';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import * as rax from 'retry-axios';\nimport axios, { AxiosInstance } from 'axios';\n\ninterface MyRaxConfig extends rax.RaxConfig {\n  // Optionally extend raxConfig if needed\n}\n\nconst myAxiosInstance: AxiosInstance = axios.create();\n\n// Configure retry-axios for this specific instance\nmyAxiosInstance.defaults.raxConfig = {\n  retry: 5, // Retry 5 times\n  retryDelay: 500, // 500ms delay between retries\n  statusCodesToRetry: [[429, 429], [500, 599]], // Only retry for Too Many Requests and 5xx errors\n  backoffType: 'exponential', // Use exponential backoff\n  jitter: 'full', // Add full jitter\n  onError: (err) => {\n    const cfg = rax.getConfig(err);\n    if (cfg) {\n      console.log(`Retry attempt #${cfg.currentRetryAttempt + 1} for URL: ${err.config?.url}`);\n    }\n  }\n} as MyRaxConfig;\n\n// Attach the retry interceptor to the custom instance\nrax.attach(myAxiosInstance);\n\nasync function fetchData() {\n  try {\n    // Simulate an API call that might fail and need retries\n    // Using httpbin.org for demonstration purposes.\n    // In a real scenario, this might be a flaky backend endpoint.\n    const response = await myAxiosInstance.get('https://httpbin.org/status/503');\n    console.log('Successfully fetched data:', response.data);\n  } catch (error: any) {\n    if (error.response) {\n      console.error(`Failed to fetch data after retries. Status: ${error.response.status}`);\n    } else if (error.request) {\n      console.error('Failed to fetch data after retries. No response received.');\n    } else {\n      console.error('Error during request setup:', error.message);\n    }\n  }\n}\n\nfetchData();","lang":"typescript","description":"This quickstart demonstrates how to create a custom Axios instance, configure `retry-axios` for it with specific retry policies (count, delay, status codes, backoff, jitter), and attach the retry interceptor. It includes an `onError` callback for logging and illustrates fetching data from an endpoint that might return a retryable status code, showcasing the retry mechanism in action.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}