These libraries provide functionality to automatically retry failed HTTP requests, which is essential for improving the resilience of applications that rely on external APIs. They help manage transient errors, such as network issues or server timeouts, by implementing retry logic based on configurable parameters. This ensures that applications can handle temporary failures gracefully, enhancing user experience and reliability.
Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
axios-retry
5,206,047
2,006
33.6 kB
58
a year ago
Apache-2.0
fetch-retry
3,103,649
317
55.2 kB
6
2 years ago
MIT
node-fetch-retry
45,435
9
7.94 kB
3
-
MIT
Feature Comparison: axios-retry vs fetch-retry vs node-fetch-retry
Integration
axios-retry:
axios-retry is designed specifically for Axios, making it easy to implement retry logic without altering your existing Axios configuration. It supports all Axios features, including interceptors, which allows for a smooth integration into your application.
fetch-retry:
fetch-retry works directly with the Fetch API, providing a straightforward way to add retry logic. It does not require any additional libraries, making it a lightweight choice for projects that use the Fetch API natively.
node-fetch-retry:
node-fetch-retry integrates with node-fetch, ensuring that retry logic is applied seamlessly in server-side applications. It is built to work with the fetch API in Node.js, maintaining consistency across client and server requests.
Configuration Options
axios-retry:
axios-retry offers extensive configuration options, allowing you to customize the retry behavior, such as the number of retries, retry delay, and conditions for retrying requests. This flexibility enables developers to fine-tune the retry logic to suit specific application needs.
fetch-retry:
fetch-retry provides basic configuration options for setting the number of retries and delay between attempts. However, it may not offer as many customization options as axios-retry, making it simpler but less flexible for complex scenarios.
node-fetch-retry:
node-fetch-retry allows for similar configuration options as fetch-retry, enabling customization of retry attempts and delays. It is designed to be straightforward, focusing on essential retry logic without overwhelming the developer with options.
Error Handling
axios-retry:
axios-retry provides built-in support for handling specific HTTP status codes, allowing you to define which errors should trigger a retry. This feature is crucial for managing different types of failures effectively, such as network errors versus server errors.
fetch-retry:
fetch-retry allows you to specify which errors should be retried, but it may require additional handling for specific HTTP status codes. Developers need to implement custom logic to manage different error scenarios, which can add complexity.
node-fetch-retry:
node-fetch-retry offers similar error handling capabilities as fetch-retry, enabling you to define retry conditions based on error types. This ensures that your application can intelligently decide when to retry requests based on the nature of the failure.
Use Cases
axios-retry:
axios-retry is ideal for applications that make frequent API calls and need robust error handling, such as web applications that rely on third-party services. Its deep integration with Axios makes it a go-to choice for many developers already using this library.
fetch-retry:
fetch-retry is suitable for smaller projects or applications that prioritize simplicity and minimal dependencies. It works well for straightforward use cases where basic retry logic is sufficient without the need for extensive customization.
node-fetch-retry:
node-fetch-retry is specifically tailored for server-side applications using node-fetch, making it a perfect fit for backend services that need to interact with external APIs reliably. It ensures that server-side requests can handle transient errors effectively.
Community and Support
axios-retry:
axios-retry benefits from a large community due to its association with Axios, which is widely used. This means better support, more examples, and a wealth of resources available for developers.
fetch-retry:
fetch-retry has a smaller community compared to axios-retry, but it is still actively maintained. Developers may find fewer resources and examples, but the simplicity of the library makes it easy to implement without extensive documentation.
node-fetch-retry:
node-fetch-retry is also part of the node-fetch ecosystem, which has a decent community. However, being a more niche library, the support may not be as extensive as axios-retry, but it is still reliable for server-side applications.
How to Choose: axios-retry vs fetch-retry vs node-fetch-retry
axios-retry:
Choose axios-retry if you are already using Axios for making HTTP requests in your application. It integrates seamlessly with Axios, allowing you to leverage its features while adding retry capabilities without significant changes to your existing codebase.
fetch-retry:
Select fetch-retry if you are using the native Fetch API and want a lightweight solution to add retry functionality. This package is ideal for projects that prioritize minimal dependencies and want to maintain a clean, native approach to HTTP requests.
node-fetch-retry:
Opt for node-fetch-retry if you are working in a Node.js environment and need a retry mechanism for the node-fetch library. This package is tailored for server-side applications, ensuring that you can handle retries effectively in a Node.js context.
Popular Comparisons
Similar Npm Packages to axios-retry
axios-retry is a popular library that enhances the functionality of Axios, a widely-used HTTP client for JavaScript. This package allows developers to automatically retry failed HTTP requests, which can be particularly useful in scenarios where network issues or server errors might temporarily prevent a request from succeeding. With configurable options for the number of retries, delay between attempts, and conditions under which to retry, axios-retry provides a robust solution for improving the reliability of API interactions in applications.
While axios-retry is a great option for adding retry functionality to Axios requests, there are alternatives available that serve similar purposes. One notable alternative is:
retry-axios. This library is built specifically for retrying Axios requests and offers a similar feature set to axios-retry. It provides automatic retries for failed requests, allowing developers to specify the number of retry attempts and the conditions under which retries should occur. retry-axios is designed to be simple to use and integrates seamlessly with Axios, making it an excellent choice for developers looking for an alternative to axios-retry.
fetch-retry is a JavaScript library that enhances the native Fetch API by adding retry functionality for failed requests. This is particularly useful when dealing with unreliable networks or APIs that may occasionally fail. With fetch-retry, developers can specify the number of retry attempts, delay between retries, and other options to ensure that their applications can gracefully handle transient errors. This library is a great choice for projects that rely heavily on the Fetch API and need robust error handling for network requests.
There are several alternatives to fetch-retry that also provide retry capabilities for HTTP requests:
axios-retry is a library designed to work with Axios, a popular promise-based HTTP client. It allows developers to automatically retry failed requests with configurable options, such as the number of retries and the delay between attempts. If you're already using Axios in your project, axios-retry is a natural choice to enhance your HTTP request handling with retry logic. It integrates seamlessly with Axios and provides a straightforward API for configuring retries.
node-fetch-retry is a retry wrapper for the node-fetch library, which is a lightweight module that brings window.fetch to Node.js. Similar to fetch-retry, node-fetch-retry allows developers to specify retry logic for failed requests made with node-fetch. This library is particularly useful for server-side applications built with Node.js that need to make HTTP requests and require robust error handling.
node-fetch-retry is a package that enhances the popular node-fetch library by adding retry functionality for failed HTTP requests. This is particularly useful when dealing with unreliable networks or APIs that may occasionally fail. With node-fetch-retry, developers can specify the number of retry attempts, delay between retries, and conditions under which retries should occur, making it a robust solution for improving the reliability of data fetching in Node.js applications.
While node-fetch-retry is a great option for adding retry logic to fetch requests, there are several alternatives in the ecosystem that provide similar functionalities. Here are a few noteworthy options:
axios-retry is a retry interceptor for the axios HTTP client. It allows developers to automatically retry requests that fail due to certain conditions, such as network errors or server responses that indicate a temporary issue. With axios-retry, you can easily configure the number of retries, delay intervals, and specific error conditions that trigger a retry, making it a powerful tool for enhancing the resilience of applications that rely on axios for HTTP requests.
fetch-retry is a simple wrapper around the native fetch API that adds retry functionality. It allows developers to specify the number of retries, delay between attempts, and conditions for retrying requests. This package is particularly useful for developers looking to enhance the native fetch API with minimal overhead while maintaining a straightforward API.
got is a powerful and flexible HTTP request library for Node.js that comes with built-in support for retries. It provides a rich set of features, including automatic retries on failure, timeout handling, and support for streams. If you are looking for a comprehensive HTTP client that includes retry logic along with many other advanced features, got is an excellent choice.
superagent-retry is a plugin for the superagent HTTP client that adds retry capabilities. It allows developers to automatically retry failed requests based on configurable conditions. If you are already using superagent in your application and need retry functionality, this plugin integrates seamlessly with the existing API.
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
Name
Type
Default
Description
retries
Number
3
The number of times to retry before failing. 1 = One retry after first failure
retryCondition
Function
isNetworkOrIdempotentRequestError
A 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).
shouldResetTimeout
Boolean
false
Defines if the timeout should be reset between retries
retryDelay
Function
function 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.
onRetry
Function
function 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.
onMaxRetryTimesExceeded
Function
function onMaxRetryTimesExceeded(error, retryCount) { return; }
After all the retries are failed, this callback will be called with the last error before throwing the error.
validateResponse
Function | null
null
A 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).