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

HTTP Request Retry Libraries

These libraries provide mechanisms to automatically retry failed HTTP requests in JavaScript applications. They are particularly useful for handling transient errors, such as network issues or server timeouts, ensuring that applications can recover gracefully from temporary failures. By implementing retries, developers can enhance the reliability of their applications and improve user experience by reducing the likelihood of failure due to intermittent 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
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 retry-axios vs retry-request vs superagent-retry

Integration

  • axios-retry:

    axios-retry integrates directly with Axios, allowing you to add retry logic with minimal configuration. It leverages Axios interceptors to handle retries seamlessly, making it easy to implement in existing Axios-based projects.

  • fetch-retry:

    fetch-retry is designed to work with the native Fetch API, providing a simple wrapper that adds retry capabilities. It is lightweight and does not require any additional dependencies, making it a good fit for modern web applications that use Fetch.

  • retry-axios:

    retry-axios extends the functionality of Axios by providing additional features like customizable retry strategies and error handling. It is built specifically for Axios users who need more control over the retry process, allowing for advanced configurations.

  • retry-request:

    retry-request is built for the request library, making it easy to add retry functionality to Node.js applications. It is straightforward to use and integrates well with the request library's API, making it suitable for server-side applications.

  • superagent-retry:

    superagent-retry is specifically designed for SuperAgent, allowing users to add retry logic to their HTTP requests easily. It fits well within the SuperAgent ecosystem, providing a seamless experience for users of that library.

Customization

  • axios-retry:

    axios-retry allows for extensive customization of retry strategies, including the ability to specify the number of retries, delay between retries, and conditions under which retries should occur. This flexibility makes it suitable for various use cases.

  • fetch-retry:

    fetch-retry provides basic customization options, such as the number of retries and delay between attempts. However, it is less flexible compared to other libraries, focusing on simplicity and ease of use.

  • retry-axios:

    retry-axios offers advanced customization options, including exponential backoff strategies and the ability to define custom retry conditions based on response status codes or error types. This makes it a powerful choice for complex applications.

  • retry-request:

    retry-request provides basic customization options, allowing users to set the number of retries and delay. It is straightforward but lacks the advanced features found in other libraries.

  • superagent-retry:

    superagent-retry allows for some customization, including the number of retries and delay between attempts. It is designed to be simple and effective without overwhelming users with options.

Error Handling

  • axios-retry:

    axios-retry provides built-in error handling capabilities, allowing users to define specific conditions under which retries should occur. This ensures that only appropriate errors trigger a retry, improving the reliability of the application.

  • fetch-retry:

    fetch-retry has basic error handling, retrying on network errors and certain HTTP status codes. However, it may not cover all edge cases, requiring developers to implement additional logic for comprehensive error handling.

  • retry-axios:

    retry-axios excels in error handling by allowing users to specify custom conditions for retries based on response status codes and error types. This level of control helps ensure that retries are only attempted when appropriate, enhancing application stability.

  • retry-request:

    retry-request provides basic error handling, retrying on network errors and certain HTTP status codes. It is straightforward but may require additional handling for more complex scenarios.

  • superagent-retry:

    superagent-retry offers basic error handling, retrying on network errors and specific HTTP status codes. It is simple to use but may not cover all scenarios, requiring additional logic for comprehensive error handling.

Performance Impact

  • axios-retry:

    axios-retry has minimal performance impact, as it only retries failed requests without adding significant overhead. This makes it suitable for applications where performance is critical, and retries are infrequent.

  • fetch-retry:

    fetch-retry is lightweight and has a low performance impact, making it ideal for applications that prioritize speed and efficiency. However, excessive retries may still affect performance in high-load scenarios.

  • retry-axios:

    retry-axios is designed to minimize performance impact while providing robust retry capabilities. It uses efficient algorithms to manage retries, ensuring that applications remain responsive even under load.

  • retry-request:

    retry-request has a low performance impact, as it only retries failed requests. However, like other libraries, excessive retries can lead to performance degradation in high-load situations.

  • superagent-retry:

    superagent-retry is lightweight and has minimal performance overhead, making it suitable for applications where performance is a concern. It efficiently manages retries without introducing significant delays.

Learning Curve

  • axios-retry:

    axios-retry has a gentle learning curve, especially for developers already familiar with Axios. Its straightforward API and integration make it easy to implement without extensive documentation.

  • fetch-retry:

    fetch-retry is easy to learn, particularly for developers accustomed to the Fetch API. Its simplicity and minimal configuration requirements make it accessible to newcomers.

  • retry-axios:

    retry-axios may have a slightly steeper learning curve due to its advanced features and customization options. However, developers familiar with Axios will find it manageable.

  • retry-request:

    retry-request is simple to learn and implement, especially for those already using the request library. Its straightforward API allows for quick integration into existing projects.

  • superagent-retry:

    superagent-retry has a low learning curve for developers familiar with SuperAgent. Its integration is seamless, making it easy to add retry functionality without extensive setup.

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

  • axios-retry:

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

  • fetch-retry:

    Select fetch-retry if you are using the Fetch API and want a lightweight solution to add retry capabilities. It is ideal for projects that prefer native browser APIs and need minimal overhead, making it a good choice for modern web applications.

  • retry-axios:

    Opt for retry-axios if you want to extend Axios with more advanced retry capabilities, including exponential backoff strategies and better error handling. This package is suitable for applications that require more control over the retry process and need to handle various error types effectively.

  • retry-request:

    Use retry-request if you are working with the request library and need a straightforward way to implement retries. It is designed for Node.js applications and is perfect for server-side HTTP requests, providing a simple API for retrying requests.

  • superagent-retry:

    Choose superagent-retry if you are utilizing the SuperAgent library for making HTTP requests and need to add retry logic. This package is tailored for SuperAgent users and provides a clean integration for retrying failed requests.

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