axios-retry vs fetch-retry vs got vs retry-axios vs superagent-retry
HTTP Request Retry Libraries
axios-retryfetch-retrygotretry-axiossuperagent-retrySimilar Packages:

HTTP Request Retry Libraries

HTTP request retry libraries are designed to enhance the reliability of network requests by automatically retrying failed requests based on specified criteria. These libraries help developers handle transient errors, such as network issues or server unavailability, ensuring that applications can gracefully recover from temporary failures without requiring manual intervention. They provide configurable options for retry strategies, including exponential backoff, maximum retries, and specific error handling, making it easier to build robust applications that communicate over HTTP.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
axios-retry02,01233.6 kB582 years agoApache-2.0
fetch-retry031755.2 kB62 years agoMIT
got014,876304 kB12 months agoMIT
retry-axios050257.8 kB04 months agoApache-2.0
superagent-retry085-1010 years ago-

Feature Comparison: axios-retry vs fetch-retry vs got vs retry-axios vs superagent-retry

Integration

  • axios-retry:

    axios-retry integrates directly with Axios, allowing you to add retry functionality with minimal configuration. It leverages Axios interceptors to manage retries seamlessly within your existing request flow.

  • fetch-retry:

    fetch-retry is designed to work specifically with the Fetch API, making it easy to add retry capabilities without altering the core Fetch implementation. This ensures compatibility with existing Fetch-based code.

  • got:

    Got is a standalone HTTP request library that includes built-in retry functionality. It is designed to work out of the box, providing a comprehensive solution for making HTTP requests with retry logic included.

  • retry-axios:

    retry-axios is an extension of Axios that provides enhanced retry capabilities. It allows you to configure retry strategies directly within your Axios instance, making it easy to manage retries alongside other Axios features.

  • superagent-retry:

    superagent-retry integrates with Superagent, allowing you to implement retry logic while keeping the familiar Superagent API. This makes it easy to enhance your existing Superagent requests with retries.

Retry Strategy

  • axios-retry:

    axios-retry supports customizable retry strategies, including exponential backoff, which allows you to specify the delay between retries. This helps to avoid overwhelming the server during transient failures.

  • fetch-retry:

    fetch-retry allows you to define retry conditions based on HTTP status codes or network errors, giving you control over when to retry requests. It also supports configurable retry delays.

  • got:

    Got provides a robust retry strategy that includes options for maximum retries, retry delay, and error codes to retry on. This flexibility makes it suitable for a wide range of use cases.

  • retry-axios:

    retry-axios offers advanced retry strategies, including the ability to customize the retry delay and specify which HTTP status codes should trigger a retry. This level of control is beneficial for applications with specific error handling needs.

  • superagent-retry:

    superagent-retry allows you to configure retry options such as maximum attempts and delay between retries. This ensures that you can tailor the retry logic to fit your application's requirements.

Error Handling

  • axios-retry:

    axios-retry provides built-in error handling that allows you to specify which errors should trigger a retry. This includes handling network errors and specific HTTP status codes, ensuring that retries are only attempted when appropriate.

  • fetch-retry:

    fetch-retry allows you to define custom error handling logic, enabling you to specify which types of errors should be retried. This gives you the flexibility to handle different scenarios based on your application's needs.

  • got:

    Got includes advanced error handling capabilities, allowing you to catch and respond to errors in a structured way. It provides detailed error information, making it easier to diagnose issues during retries.

  • retry-axios:

    retry-axios offers comprehensive error handling, allowing you to customize how errors are processed and which errors trigger a retry. This is useful for applications that need specific error management strategies.

  • superagent-retry:

    superagent-retry provides basic error handling for retries, focusing on network errors and specific HTTP status codes. This simplicity makes it easy to implement without adding complexity.

Configuration Flexibility

  • axios-retry:

    axios-retry allows for extensive configuration options, enabling you to customize retry behavior based on your application's requirements. This includes setting maximum retries, delay strategies, and specific error conditions.

  • fetch-retry:

    fetch-retry is lightweight and provides a straightforward configuration interface, making it easy to set up retry logic without overwhelming complexity. This is ideal for projects that prioritize simplicity.

  • got:

    Got offers a high degree of configuration flexibility, allowing you to customize every aspect of the HTTP request and retry process. This makes it suitable for complex applications that require detailed control.

  • retry-axios:

    retry-axios allows you to configure retries directly within your Axios instance, providing a familiar interface for developers already using Axios. This makes it easy to integrate into existing projects.

  • superagent-retry:

    superagent-retry offers basic configuration options that are easy to understand and implement. This simplicity is beneficial for developers looking for quick and effective retry functionality.

Community Support

  • axios-retry:

    axios-retry benefits from the large Axios community, ensuring that you have access to extensive documentation, examples, and community support for troubleshooting and best practices.

  • fetch-retry:

    fetch-retry is part of the growing ecosystem around the Fetch API, with a supportive community that provides resources and examples for implementing retry logic effectively.

  • got:

    Got has a strong community and is well-documented, providing users with a wealth of resources for understanding and utilizing its features, including retries.

  • retry-axios:

    retry-axios has a supportive community due to its connection with Axios, offering resources and examples for implementing retry strategies effectively within Axios applications.

  • superagent-retry:

    superagent-retry benefits from the established Superagent community, providing users with access to documentation and community-driven support for implementing retry logic.

How to Choose: axios-retry vs fetch-retry vs got vs retry-axios vs superagent-retry

  • axios-retry:

    Choose axios-retry if you are already using Axios for HTTP requests and need a simple way to add retry functionality without changing your existing code structure. It integrates seamlessly with Axios and offers customizable retry logic.

  • fetch-retry:

    Choose fetch-retry if you are using the native Fetch API and want to add retry capabilities. It is lightweight and allows you to extend the Fetch API with minimal overhead, making it ideal for projects that prioritize native solutions.

  • got:

    Choose got if you need a comprehensive HTTP request library with built-in retry functionality. Got is designed for Node.js and offers a rich feature set, including support for streams, promises, and advanced error handling, making it suitable for more complex applications.

  • retry-axios:

    Choose retry-axios if you want to extend Axios with advanced retry capabilities. It allows for more complex retry strategies and integrates well with existing Axios configurations, making it a good choice for applications that require detailed control over retry behavior.

  • superagent-retry:

    Choose superagent-retry if you are using Superagent for HTTP requests and need to add retry logic. It provides a straightforward way to implement retries while maintaining the simplicity and readability of Superagent's API.

README for axios-retry

axios-retry

Node.js CI

Axios plugin that intercepts failed requests and retries them whenever possible.

Installation

npm install axios-retry

Usage

// CommonJS
// const axiosRetry = require('axios-retry').default;

// ES6
import axiosRetry from 'axios-retry';

axiosRetry(axios, { retries: 3 });

axios.get('http://example.com/test') // The first request fails and the second returns 'ok'
  .then(result => {
    result.data; // 'ok'
  });

// Exponential back-off retry delay between requests
axiosRetry(axios, { retryDelay: axiosRetry.exponentialDelay });

// Liner retry delay between requests
axiosRetry(axios, { retryDelay: axiosRetry.linearDelay() });

// Custom retry delay
axiosRetry(axios, { retryDelay: (retryCount) => {
  return retryCount * 1000;
}});

// Works with custom axios instances
const client = axios.create({ baseURL: 'http://example.com' });
axiosRetry(client, { retries: 3 });

client.get('/test') // The first request fails and the second returns 'ok'
  .then(result => {
    result.data; // 'ok'
  });

// Allows request-specific configuration
client
  .get('/test', {
    'axios-retry': {
      retries: 0
    }
  })
  .catch(error => { // The first request fails
    error !== undefined
  });

Note: Unless shouldResetTimeout is set, the plugin interprets the request timeout as a global value, so it is not used for each retry but for the whole request lifecycle.

Options

NameTypeDefaultDescription
retriesNumber3The number of times to retry before failing. 1 = One retry after first failure
retryConditionFunctionisNetworkOrIdempotentRequestErrorA callback to further control if a request should be retried. By default, it retries if it is a network error or a 5xx error on an idempotent request (GET, HEAD, OPTIONS, PUT or DELETE).
shouldResetTimeoutBooleanfalseDefines if the timeout should be reset between retries
retryDelayFunctionfunction noDelay() { return 0; }A callback to further control the delay in milliseconds between retried requests. By default there is no delay between retries. Another option is exponentialDelay (Exponential Backoff) or linearDelay. The function is passed retryCount and error.
onRetryFunctionfunction onRetry(retryCount, error, requestConfig) { return; }A callback to notify when a retry is about to occur. Useful for tracing and you can any async process for example refresh a token on 401. By default nothing will occur. The function is passed retryCount, error, and requestConfig.
onMaxRetryTimesExceededFunctionfunction onMaxRetryTimesExceeded(error, retryCount) { return; }After all the retries are failed, this callback will be called with the last error before throwing the error.
validateResponseFunction | nullnullA callback to define whether a response should be resolved or rejected. If null is passed, it will fallback to the axios default (only 2xx status codes are resolved).

Testing

Clone the repository and execute:

npm test

Contribute

  1. Fork it: git clone https://github.com/softonic/axios-retry.git
  2. Create your feature branch: git checkout -b feature/my-new-feature
  3. Commit your changes: git commit -am 'Added some feature'
  4. Check the build: npm run build
  5. Push to the branch: git push origin my-new-feature
  6. Submit a pull request :D