axios-retry vs fetch-retry vs got vs node-fetch-retry vs superagent-retry
HTTP Request Libraries with Retry Functionality
axios-retryfetch-retrygotnode-fetch-retrysuperagent-retrySimilar Packages:

HTTP Request Libraries with Retry Functionality

These libraries enhance HTTP request capabilities in Node.js and browser environments by providing built-in retry mechanisms. They are designed to handle transient errors, ensuring that requests are retried automatically without requiring additional logic from the developer. This is particularly useful in scenarios where network reliability is a concern, as it improves the robustness of applications by minimizing the impact of temporary failures.

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 kB13 months agoMIT
node-fetch-retry097.94 kB3-MIT
superagent-retry085-1010 years ago-

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

Integration

  • axios-retry:

    Integrates directly with Axios, allowing you to leverage existing Axios configurations and interceptors while adding retry logic seamlessly.

  • fetch-retry:

    Works as a wrapper around the Fetch API, enabling retry functionality without altering the core fetch implementation, making it easy to adopt in existing codebases.

  • got:

    Built into the Got library, providing a comprehensive solution for HTTP requests with retry capabilities, making it a one-stop solution for developers.

  • node-fetch-retry:

    Enhances node-fetch by adding retry logic, maintaining a familiar API for those used to the Fetch API in a Node.js context.

  • superagent-retry:

    Extends Superagent's functionality, allowing users to maintain their existing Superagent codebase while adding retry capabilities effortlessly.

Customization

  • axios-retry:

    Offers extensive customization options for retry strategies, including the ability to specify which status codes should trigger a retry and the delay between retries.

  • fetch-retry:

    Allows customization of retry attempts and delay intervals, giving developers control over how retries are handled based on their application's needs.

  • got:

    Provides advanced customization options, including retry on specific status codes, custom error handling, and configurable retry delays, making it highly flexible for various use cases.

  • node-fetch-retry:

    Supports customizable retry options, allowing developers to specify the number of retries and delay between attempts, ensuring it fits specific application requirements.

  • superagent-retry:

    Allows for configuration of retry attempts and delay, enabling developers to tailor the retry behavior to suit their application's needs.

Error Handling

  • axios-retry:

    Handles errors gracefully by allowing retries on specific HTTP status codes, which can be configured, thus improving user experience during transient failures.

  • fetch-retry:

    Provides a simple way to manage errors by retrying failed requests, which is particularly useful for handling network issues in client-side applications.

  • got:

    Includes robust error handling capabilities, allowing retries based on response status and providing detailed error messages to aid in debugging.

  • node-fetch-retry:

    Facilitates error handling by automatically retrying failed requests, which helps maintain application stability during network fluctuations.

  • superagent-retry:

    Enhances Superagent's error handling by adding retry logic, allowing for improved resilience against temporary network issues.

Performance

  • axios-retry:

    Minimal performance overhead due to its integration with Axios, ensuring that retry logic does not significantly impact the overall request performance.

  • fetch-retry:

    Lightweight and efficient, it adds minimal overhead to fetch requests, making it suitable for performance-sensitive applications.

  • got:

    Optimized for performance with built-in retry logic, ensuring that retries are handled efficiently without unnecessary delays.

  • node-fetch-retry:

    Maintains the performance characteristics of node-fetch while adding retry capabilities, ensuring that applications remain responsive.

  • superagent-retry:

    Offers good performance with minimal impact on request speed, allowing for efficient handling of retries without sacrificing responsiveness.

Community Support

  • axios-retry:

    Backed by a large community due to its association with Axios, ensuring ample resources and support are available for developers.

  • fetch-retry:

    While not as widely used as Axios, it benefits from the popularity of the Fetch API, with a growing community and support resources.

  • got:

    Has a strong community and extensive documentation, making it easy for developers to find help and examples for implementing retries effectively.

  • node-fetch-retry:

    Supported by the node-fetch community, providing access to resources and discussions related to its use and best practices.

  • superagent-retry:

    Part of the Superagent ecosystem, it enjoys community support and resources, making it easier for developers to implement and troubleshoot.

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

  • axios-retry:

    Choose axios-retry if you are already using Axios for your HTTP requests and need a straightforward way to add retry functionality. It integrates seamlessly with Axios and allows for customizable retry strategies based on response status codes or errors.

  • fetch-retry:

    Select fetch-retry if you are using the Fetch API and want to add retry capabilities without changing your existing fetch calls. It is lightweight and works well in browser environments, making it ideal for client-side applications.

  • got:

    Opt for got if you need a powerful HTTP request library with built-in retry support and advanced features like streams and cancellation. Got is well-suited for server-side applications and offers a rich set of options for handling requests and responses.

  • node-fetch-retry:

    Use node-fetch-retry if you prefer a lightweight implementation of the Fetch API for Node.js with retry capabilities. It is a good choice for projects that require a familiar fetch interface in a Node.js environment without additional overhead.

  • superagent-retry:

    Choose superagent-retry if you are using Superagent and want to enhance its capabilities with retry functionality. It is particularly useful for projects that already utilize Superagent for making HTTP requests and need a simple way to handle 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