{"id":48716,"library":"nice-axios","title":"NiceAxios","description":"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.","status":"active","version":"0.1.33","language":"javascript","source_language":"en","source_url":"https://github.com/sixdjango/nice-axios","tags":["javascript","rollup","axios","vitest","vitepress","typescript","react","vue","nodejs"],"install":[{"cmd":"npm install nice-axios","lang":"bash","label":"npm"},{"cmd":"yarn add nice-axios","lang":"bash","label":"yarn"},{"cmd":"pnpm add nice-axios","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core HTTP client dependency; NiceAxios wraps Axios instances.","package":"axios","optional":false}],"imports":[{"note":"Default export is not available; must use named import.","wrong":"import NiceAxios from 'nice-axios'","symbol":"createNiceAxios","correct":"import { createNiceAxios } from 'nice-axios'"},{"note":"NiceAxiosPlugin is a TypeScript type; use `import type` to avoid runtime errors in some bundlers.","wrong":"import { NiceAxiosPlugin } from 'nice-axios'","symbol":"NiceAxiosPlugin","correct":"import type { NiceAxiosPlugin } from 'nice-axios'"},{"note":"NiceAxiosExecutor is a TypeScript type; must be imported as a type.","wrong":"import { NiceAxiosExecutor } from 'nice-axios'","symbol":"NiceAxiosExecutor","correct":"import type { NiceAxiosExecutor } from 'nice-axios'"}],"quickstart":{"code":"import { createNiceAxios } from 'nice-axios';\nimport axios, { AxiosResponse } from 'axios';\n\n// Define a simple plugin to add a token header\nconst addTokenPlugin = async (next, config) => {\n    // Modify config before request\n    if (config?.headers) {\n        config.headers['Authorization'] = 'Bearer ' + (process.env.API_TOKEN ?? 'default-token');\n    }\n    return next(config).then((result) => {\n        // Modify response if needed\n        return result;\n    });\n};\n\n// Create NiceAxios instance with plugins\nconst niceAxios = createNiceAxios(\n    { baseURL: 'https://api.example.com' },\n    [\n        {\n            order: -100, // Runs first before request, last after response\n            executor: addTokenPlugin,\n            desc: 'Add authorization token',\n        },\n    ]\n);\n\n// Make a request\nniceAxios.get<AxiosResponse>('/data').then(console.log).catch(console.error);","lang":"typescript","description":"Shows how to create a NiceAxios instance with a custom plugin that adds an Authorization header to every request."},"warnings":[{"fix":"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).","message":"Plugin order: lower order values execute first before the request, but after the request they execute in reverse order (higher order first). Misunderstanding the order logic can lead to unexpected middleware execution.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Avoid relying on undocumented options; stick to the documented `createNiceAxios` signature and plugin interface.","message":"The package documentation mentions an 'afterPluginOption' and 'AjaxConfigMeta', but these types/options are not exported and may be removed in future versions.","severity":"deprecated","affected_versions":">=0.1.0"},{"fix":"Clone the config object before mutation if you need to isolate changes, e.g., `const newConfig = { ...config, headers: { ...config.headers, 'X-Custom': 'value' } };`","message":"The `config` object passed to plugin executors is the same reference throughout the request lifecycle. Mutating it will affect subsequent plugins and the final Axios request.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Ensure axios is in your package.json dependencies: `npm install axios`","message":"The library does not bundle Axios; you must install `axios` separately as a dependency.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Include lodash script tag before the nice-axios UMD script.","message":"CDN usage: the UMD build expects axios and lodash to be available globally. If lodash is not present, it may cause runtime errors.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.1.33':32 'ad':72 'allow':34 'around':9 'authent':78 'axio':10,68,90 'base':7 'compos':37,56 'concern':76 'cross':74 'cross-cut':73 'current':29 'custom':38 'cut':75 'develop':35 'easi':61 'error':81 'execut':42 'exist':67 'extens':62 'function':57 'handl':82 'higher':49 'http':25 'ideal':70 'implement':12 'inspir':18 'instanc':69 'integr':65 'intercept':22 'javascript':88 'koa':20 'like':77 'log':79 'lower':43 'middlewar':16 'model':15 'modular':85 'niceaxio':1,2 'nodej':96 'onion':14 'order':41,44 'pattern':17 'plugin':6,39 'plugin-bas':5 'post':52 'post-respons':51 'pre':47 'pre-request':46 'process':24 'react':94 'request':26,48 'respons':28,53 'reusabl':86 'rollup':89 'seamless':64 'stabl':30 'support':58 'type':60 'typescript':59,93 'use':54 'version':31 'vitepress':92 'vitest':91 'vue':95 'way':87 'wrapper':8","created_at":"2026-06-07T16:58:05.634475+00:00","updated_at":"2026-06-07T16:58:05.634475+00:00","problems":[{"fix":"Add null check in plugin: `if (config?.headers) { ... }`","cause":"Plugin executor is called with undefined config when no Axios config is provided.","error":"TypeError: Cannot read properties of undefined (reading 'headers')"},{"fix":"Use `import type { NiceAxiosPlugin } from 'nice-axios'`","cause":"Trying to import a type at runtime without using `import type`.","error":"Module '\"nice-axios\"' has no exported member 'NiceAxiosPlugin'."},{"fix":"Add `<script src=\"https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js\"></script>` before the nice-axios UMD script.","cause":"Using the UMD build without including axios script first.","error":"Uncaught TypeError: axios is not a function"},{"fix":"Ensure your plugin executor calls `next(config)` and returns the promise chain.","cause":"Plugin executor is not returning `next(config).then(...)` correctly.","error":"TypeError: next is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/sixdjango","github":"https://github.com/sixdjango/nice-axios","docs":null,"changelog":null,"pypi":null,"npm":"nice-axios","openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}