Registry / devops / axios-url-template

axios-url-template

JSON →
library1.0.3jsnpmunverified

Axios interceptor that adds RFC 6570 URI Template support, allowing dynamic URL construction via urlTemplate and urlTemplateParams config fields. Version 1.0.3 ships TypeScript types and wraps the url-template library. Key differentiators: works as a request interceptor, persists both the template and params in the Axios config after expansion, and supports a urlAsTemplate option that treats the plain url field as a template by default. It has a small install size and is designed for automating low-cardinality route logging or metrics.

npm install axios-url-template
INSTALL
IMPORT
SIG · AXIOS-URL-TEMPLATE
A
axios-url-template
devopsjavascriptv1.0.3
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.

urlTemplateInterceptor
import { urlTemplateInterceptor } from 'axios-url-template'
const urlTemplateInterceptor = require('axios-url-template')
ESM and TypeScript support only. CommonJS require returns the module object, use require('axios-url-template').urlTemplateInterceptor for backwards compat.
useUrlTemplateInterceptor
import { useUrlTemplateInterceptor } from 'axios-url-template'
import useUrlTemplateInterceptor from 'axios-url-template'
This is a named export, not a default export.
UrlTemplateInterceptorOptions
import { UrlTemplateInterceptorOptions } from 'axios-url-template'
import { Options } from 'axios-url-template'
TypeScript type for the options object. Avoid using a generic name that may conflict.

Shows how to import, register the interceptor, and make a request using urlTemplateParams.

import axios from 'axios'; import { urlTemplateInterceptor } from 'axios-url-template'; // Register interceptor globally axios.interceptors.request.use(urlTemplateInterceptor()); // Optional: use shortcut function // import { useUrlTemplateInterceptor } from 'axios-url-template'; // useUrlTemplateInterceptor(axios); // Make a request with URL template axios.get('/users/{userId}', { urlTemplateParams: { userId: 42 }, }).then(response => { console.log(response.config.url); // '/users/42' console.log(response.config.urlTemplate); // '/users/{userId}' console.log(response.config.urlTemplateParams); // { userId: 42 } });
Debug
Known issues
gotchaurlAsTemplate defaults to true, meaning the url field is always treated as a template if present. This can cause unexpected expansion if your URLs contain characters that look like template expressions (e.g., {id}).
fix
Set urlAsTemplate: false in options when you do not want automatic template expansion of url.
affects: >=0.0.0
gotchaIf both url and urlTemplate are provided, urlTemplate takes precedence and url is ignored for expansion. However, urlAsTemplate will still apply to url if urlTemplate is missing.
fix
Provide only one of url or urlTemplate to avoid confusion.
affects: >=0.0.0
gotchaInterceptor mutates the request config object in place. If you reuse config objects across requests, the original url may be overwritten.
fix
Clone configs before passing them to multiple requests, or avoid reuse.
affects: >=0.0.0
deprecatedNo deprecated features identified.
Errors
Common errors & fixes
TypeError: axios.interceptors.request.use is not a function
Axios is not properly imported or is a different version where interceptors API changed.
fix
Ensure you import axios correctly: import axios from 'axios'; (ESM) or const axios = require('axios'); (CJS). Use axios version 0.x or 1.x.
Cannot find module 'axios-url-template'
Package not installed or import path is wrong.
fix
Run npm install axios-url-template. Check that the package is in node_modules.
urlTemplate is not a function
Interference with another interceptor or the interceptor was not properly attached.
fix
Ensure urlTemplateInterceptor is called (returns a function) and passed to use(). Example: axios.interceptors.request.use(urlTemplateInterceptor()).
Property 'urlTemplateParams' does not exist on type 'AxiosRequestConfig'
TypeScript is strict and the axios types do not include custom properties.
fix
Extend AxiosRequestConfig via module augmentation: declare module 'axios' { interface AxiosRequestConfig { urlTemplateParams?: Record<string, unknown>; urlTemplate?: string; } }
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
axiosrequiredpeer dependency - this library extends Axios with an interceptor
url-templaterequiredruntime dependency for URI template expansion per RFC 6570
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
axios-url-template — npm install axios-url-template · libregistry