{"id":18143,"library":"ax-middleware","title":"axios-middleware","description":"A simple middleware service for axios HTTP requests. Version 0.4.0 is the final release as the package is deprecated. It allows intercepting axios requests and responses via middleware functions, supporting async handlers and custom adapters. Key differentiators: a clean middleware pattern with onRequest/onResponse/onSync hooks, vs axios's native interceptors. Requires axios >=0.17.1 <1.2.0. The package is unmaintained and alternatives should be considered.","status":"deprecated","version":"0.4.0","language":"javascript","source_language":"en","source_url":"https://github.com/emileber/axios-middleware","tags":["javascript","axios","request","adapter","middleware","response","http"],"install":[{"cmd":"npm install ax-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add ax-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add ax-middleware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM import for the service class.","wrong":"const axiosMiddleware = require('axios-middleware')","symbol":"HttpMiddlewareService","correct":"import { HttpMiddlewareService } from 'axios-middleware'"},{"note":"Alias for HttpMiddlewareService. Both are the same.","symbol":"Service","correct":"import { Service } from 'axios-middleware'"},{"note":"Since v0.3.0, the HttpMiddleware base class was removed. Use a plain object with onRequest/onResponse/onSync methods.","wrong":"class MyMiddleware extends HttpMiddleware { onRequest(config) {} }","symbol":"Middleware interface","correct":"const myMiddleware = { onRequest(config) { return config; } }"}],"quickstart":{"code":"import axios from 'axios';\nimport { HttpMiddlewareService } from 'axios-middleware';\n\nconst service = new HttpMiddlewareService(axios);\n\n// Add a middleware that logs requests\nservice.register({\n  onRequest(config) {\n    console.log('Request:', config.url);\n    return config;\n  },\n  onResponse(response) {\n    console.log('Response:', response.status);\n    return response;\n  },\n  onSync(config, req) {\n    // Sync handlers if using an adapter that blocks\n    return config;\n  }\n});\n\n// Use axios as normal\naxios.get('/api/data')\n  .then(res => console.log(res.data))\n  .catch(err => console.error(err));","lang":"typescript","description":"Shows how to create a middleware service, register a middleware with request/response/sync handlers, and use axios normally."},"warnings":[{"fix":"Migrate to a maintained alternative like axios interceptors or a modern HTTP client library (e.g., ky, got).","message":"axios-middleware is deprecated and no longer maintained. The last version (0.4.0) is the end-of-life release.","severity":"deprecated","affected_versions":">=0.4.0"},{"fix":"Change any middleware defined as class MyMiddleware extends HttpMiddleware to a plain object with onRequest/onResponse/onSync methods.","message":"From v0.3.0, the HttpMiddleware base class was removed. Middleware must be plain objects, not class instances.","severity":"breaking","affected_versions":">=0.3.0"},{"fix":"Update middleware handlers to use the new 'on' prefix naming convention.","message":"In v0.1.3, handler method names changed: 'handleRequestError' became 'onRequestError', 'handleResponseError' became 'onResponseError'.","severity":"breaking","affected_versions":"<=0.1.2"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install axios-middleware' (ensure axios is also installed as a peer dependency).","cause":"The package was not installed or is not in node_modules.","error":"Cannot find module 'axios-middleware'"},{"fix":"Use a plain object for middleware instead of a class inheriting from HttpMiddleware.","cause":"Attempting to use the deprecated HttpMiddleware base class (removed in v0.3.0).","error":"Class extends HttpMiddleware is not a constructor"},{"fix":"Ensure you instantiate service with: new HttpMiddlewareService(axios).","cause":"The HttpMiddlewareService instance was not created correctly or axios is not passed.","error":"TypeError: Cannot read property 'register' of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}