axios-middleware is a utility library designed to simplify the creation and management of HTTP middleware for Axios, aiming to offer more flexibility and testability compared to native Axios interceptors. It allows developers to register middleware objects with methods like `onRequest`, `onResponse`, and `onResponseError` to hook into different stages of a request lifecycle. The current stable version is 0.4.0, which was released as an 'End of life' version. The package is now abandoned, with the maintainer recommending alternatives due to breaking changes in newer Axios versions and a shift in recommended HTTP client practices. It supports Node.js environments and had a peer dependency on Axios versions `>=0.17.1 <1.2.0`.
npm install axios-middlewareVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `axios-middleware` with an Axios instance, register request and response interceptors, and then make API calls, showcasing both success and error handling.
Refactor middleware classes to no longer extend `HttpMiddleware`. Instead, use plain objects or classes implementing the handler methods (`onRequest`, `onResponse`, etc.) directly with `middleware.use()`.
Rename middleware handler methods (e.g., `handleRequest` to `onRequest`, `handleResponseError` to `onResponseError`).
It is strongly recommended to migrate to an alternative solution or directly use Axios's built-in interceptors. Continuing to use this package may lead to compatibility issues with newer Axios versions and lack of security updates.
Either downgrade your `axios` version to match the peer dependency range (`<1.2.0`) or, preferably, migrate away from `axios-middleware` to a maintained solution that supports modern Axios versions or use Axios's native interceptors.
Remove the `extends HttpMiddleware` clause from your middleware class definition. Implement handler methods directly or use plain objects for middleware.
Update method names from `handleX` to `onX` (e.g., `handleRequestError` becomes `onRequestError`, `handleResponse` becomes `onResponse`).
Ensure `axiosMiddleware` is instantiated with a valid `axios` instance created using `axios.create()` or the global `axios` object.