NiceAxios is a plugin-based wrapper around Axios that implements the 'onion model' middleware pattern (inspired by Koa) for intercepting and processing HTTP requests and responses. Current stable version: 0.1.33. It allows developers to compose custom plugins with ordered execution (lower order for pre-request, higher for post-response) using a compose function. Supports TypeScript types, easy extension, and seamless integration with existing Axios instances. Ideal for adding cross-cutting concerns like authentication, logging, and error handling in a modular, reusable way.
npm install nice-axiosNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to create a NiceAxios instance with a custom plugin that adds an Authorization header to every request.
Set pre-request plugins with negative order values (e.g., -100 for early execution) and post-response plugins with positive order values (e.g., 100 for early execution after request).
Avoid relying on undocumented options; stick to the documented `createNiceAxios` signature and plugin interface.
Clone the config object before mutation if you need to isolate changes, e.g., `const newConfig = { ...config, headers: { ...config.headers, 'X-Custom': 'value' } };`Ensure axios is in your package.json dependencies: `npm install axios`
Include lodash script tag before the nice-axios UMD script.
Add null check in plugin: `if (config?.headers) { ... }`Use `import type { NiceAxiosPlugin } from 'nice-axios'`Add `<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>` before the nice-axios UMD script.
Ensure your plugin executor calls `next(config)` and returns the promise chain.