Registry / testing / axios-middlware

axios-middlware

JSON →
library0.4.0jsnpmunverified

A lightweight middleware service for axios HTTP requests, allowing you to intercept and transform requests and responses using a clean middleware pattern. Current stable version is 0.4.0, released in 2018. It is designed for axios versions >=0.17.1 <1.2.0. Differentiator: provides an easy-to-use middleware stack similar to Express, rather than relying on axios interceptors directly.

npm install axios-middlware
INSTALL
IMPORT
SIG · AXIOS-MIDDLWARE
A
axios-middlware
testingjavascriptv0.4.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AxiosMiddleware
import { AxiosMiddleware } from 'axios-middleware'
import AxiosMiddleware from 'axios-middleware'
The package exports a named class, not a default export.
Middleware
import { Middleware } from 'axios-middleware'
Type for defining custom middleware functions.
AxiosMiddleware (CommonJS)
const { AxiosMiddleware } = require('axios-middleware');
const AxiosMiddleware = require('axios-middleware');
CJS users must destructure the named export.

Create an AxiosMiddleware instance, register a request middleware that adds a custom header, and make a GET request.

import axios from 'axios'; import { AxiosMiddleware } from 'axios-middleware'; const middleware = new AxiosMiddleware(axios); // Add a request middleware middleware.register({ onRequest(config) { config.headers['X-Custom-Header'] = 'value'; return config; } }); // Use axios normally, middleware intercepts axios.get('https://api.example.com/data').then(response => { console.log(response.data); });
Debug
Known issues
gotchaAxiosMiddleware must be passed the same axios instance used for requests; otherwise middleware won't apply.
fix
Use the same axios instance throughout your application.
affects: >=0.0.0
gotchaDo not call middleware.unregister() inside middleware callbacks as it modifies the stack during iteration.
fix
Avoid unregistering middleware from within its own handler; schedule it via setTimeout or use a flag.
affects: >=0.0.0
deprecatedThe package has not been updated since 2018; consider using axios interceptors directly or a more modern alternative if you need active maintenance.
fix
Switch to axios interceptors or libraries like @nestjs/axios for active support.
affects: >=0.4.0
Errors
Common errors & fixes
TypeError: axios_middleware_1.AxiosMiddleware is not a constructor
Incorrect import: default import instead of named import.
fix
Use 'import { AxiosMiddleware } from "axios-middleware";'
Cannot read properties of undefined (reading 'interceptors')
AxiosMiddleware not initialized with an axios instance.
fix
Pass an axios instance to the constructor: new AxiosMiddleware(axios)
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
axiosrequiredpeer dependency for HTTP requests
Agent activity
25 hits · last 30 days
node
22
Amazon
1
OpenAI (training)
1
Resources
axios-middlware — npm install axios-middlware · libregistry