axios-retry vs fetch-retry vs requestretry vs retry-axios vs retry-request vs superagent-retry
HTTP Request Retry Libraries
axios-retryfetch-retryrequestretryretry-axiosretry-requestsuperagent-retrySimilar Packages:

HTTP Request Retry Libraries

These libraries are designed to enhance HTTP request handling by automatically retrying failed requests. They are particularly useful in scenarios where network reliability is an issue, such as in mobile applications or when interacting with unstable APIs. By implementing retry logic, these packages help improve the resilience of applications and ensure better user experiences by reducing the likelihood of failures due to transient issues.

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
requestretry034856.5 kB114 months agoMIT
retry-axios050257.8 kB04 months agoApache-2.0
retry-request06916.1 kB37 months agoMIT
superagent-retry085-1010 years ago-

Feature Comparison: axios-retry vs fetch-retry vs requestretry vs retry-axios vs retry-request vs superagent-retry

Integration

  • axios-retry:

    Integrates directly with Axios, allowing you to add retry logic with minimal configuration. It leverages Axios interceptors, making it easy to implement retries without altering your existing request code.

  • fetch-retry:

    Designed to work with the Fetch API, it provides a simple wrapper around the native fetch function, enabling retry capabilities without requiring additional libraries or complex setups.

  • requestretry:

    Built to extend the request library, it adds retry functionality seamlessly, allowing you to specify retry options directly in your request calls without needing to modify your request flow.

  • retry-axios:

    Enhances Axios with advanced retry features, including exponential backoff and customizable retry conditions, making it suitable for applications that require fine-tuned control over retry behavior.

  • retry-request:

    A straightforward extension of the request library, it provides a simple API for adding retries, making it easy to implement without extensive configuration or changes to existing code.

  • superagent-retry:

    Integrates with SuperAgent, allowing users to easily add retry logic to their HTTP requests while maintaining the familiar SuperAgent syntax.

Configurability

  • axios-retry:

    Offers various configuration options such as retry count, retry delay, and conditions under which to retry, allowing developers to tailor the retry logic to their specific needs.

  • fetch-retry:

    Provides basic configuration options for retry attempts and delay, but is less configurable compared to others, making it suitable for simpler use cases.

  • requestretry:

    Highly configurable with options for retry count, delay, and custom error handling, allowing developers to define how retries should behave in different scenarios.

  • retry-axios:

    Includes extensive configuration options for retries, such as custom retry conditions and backoff strategies, making it ideal for applications with complex retry requirements.

  • retry-request:

    Offers basic configuration for retry attempts and delays, suitable for straightforward use cases without the need for extensive customization.

  • superagent-retry:

    Provides configuration options for retry attempts and delays, allowing users to customize the retry behavior while keeping the implementation simple.

Error Handling

  • axios-retry:

    Allows for custom error handling strategies, enabling developers to define specific conditions under which requests should be retried based on the error type or status code.

  • fetch-retry:

    Handles network errors gracefully, but offers limited customization for error handling compared to other libraries, making it suitable for basic scenarios.

  • requestretry:

    Includes robust error handling features, allowing developers to specify which errors should trigger a retry, providing more control over the retry process.

  • retry-axios:

    Offers advanced error handling capabilities, including the ability to retry based on specific HTTP status codes, making it suitable for applications with strict error handling requirements.

  • retry-request:

    Provides basic error handling for retries, focusing on common error scenarios without extensive customization options.

  • superagent-retry:

    Includes basic error handling for retry attempts, allowing users to define which errors should trigger a retry while keeping the implementation straightforward.

Performance

  • axios-retry:

    Optimized for performance with minimal overhead, leveraging Axios's existing capabilities to handle retries efficiently without significant impact on request speed.

  • fetch-retry:

    Lightweight and designed to have minimal impact on performance, making it suitable for applications that prioritize speed and efficiency in HTTP requests.

  • requestretry:

    Performance is generally good, but may vary depending on the complexity of the retry logic defined by the user, as it can introduce additional overhead if not configured properly.

  • retry-axios:

    Maintains high performance while adding retry capabilities, ensuring that the additional logic does not significantly slow down request processing.

  • retry-request:

    Designed for simplicity and efficiency, it provides basic retry functionality without introducing significant performance overhead.

  • superagent-retry:

    Optimized for use with SuperAgent, ensuring that retry logic is implemented efficiently without compromising the performance of HTTP requests.

Community Support

  • axios-retry:

    Backed by a large community of Axios users, it benefits from extensive documentation and community support, making it easier to find solutions and examples.

  • fetch-retry:

    As a newer package, it has a smaller community but is gaining traction among developers using the Fetch API, with growing documentation and examples available.

  • requestretry:

    Part of the well-established request library ecosystem, it has strong community support and extensive documentation, making it a reliable choice for developers.

  • retry-axios:

    Supported by a growing community of users, it has good documentation and examples available, making it easier to implement and troubleshoot.

  • retry-request:

    Being a straightforward extension of the request library, it benefits from the established community around request, providing solid support and documentation.

  • superagent-retry:

    As part of the SuperAgent ecosystem, it has a dedicated user base and good documentation, ensuring that developers can find help and resources easily.

How to Choose: axios-retry vs fetch-retry vs requestretry vs retry-axios vs retry-request vs superagent-retry

  • axios-retry:

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

  • fetch-retry:

    Opt for fetch-retry if you are using the Fetch API and need a lightweight solution to add retry capabilities. It is particularly useful for modern web applications that rely on the Fetch API and want to keep the bundle size small.

  • requestretry:

    Select requestretry if you are using the request library and need a robust solution that includes retry logic. This package is ideal for applications that already depend on request and require extensive configuration options for retries.

  • retry-axios:

    Use retry-axios if you want to extend Axios with advanced retry capabilities, including exponential backoff and customizable retry conditions. This is suitable for applications that need more control over how retries are handled.

  • retry-request:

    Choose retry-request if you are using the request library and want a straightforward way to add retry logic without complex configurations. It is best for simpler use cases where basic retry functionality suffices.

  • superagent-retry:

    Select superagent-retry if you are using SuperAgent for making HTTP requests and need to add retry functionality. This package is tailored for SuperAgent users and provides an easy way to implement retries.

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