Registry / testing / axios-deduplicator

axios-deduplicator

JSON →
library1.2.0jsnpmunverified

A simple library to deduplicate identical axios requests in-flight. Current stable version is 1.2.0, released infrequently. It intercepts requests and, if a duplicate request is detected within a configurable time window, returns the same Promise instead of making a new HTTP call. Supports custom request key generation, skip logic, and timeout. Ships TypeScript types. Lightweight alternative to more complex caching solutions.

npm install axios-deduplicator
INSTALL
IMPORT
SIG · AXIOS-DEDUPLICATOR
A
axios-deduplicator
testingjavascriptv1.2.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.

default
import createAxiosDeduplicatorInstance from 'axios-deduplicator'
const createAxiosDeduplicatorInstance = require('axios-deduplicator')
The default export is a factory function.
AxiosDeduplicator
import { AxiosDeduplicator } from 'axios-deduplicator'
import AxiosDeduplicator from 'axios-deduplicator'
Named export for the class; use it directly but remember to bind methods.
createAxiosDeduplicatorInstance (named)
import { createAxiosDeduplicatorInstance } from 'axios-deduplicator'
const createAxiosDeduplicatorInstance = require('axios-deduplicator').createAxiosDeduplicatorInstance
Both default and named exports exist; default is factory, named is also available.

Shows basic setup with axios interceptors to deduplicate identical requests. Demonstrates that the second request reuses the same Promise.

import axios from 'axios'; import createAxiosDeduplicatorInstance from 'axios-deduplicator'; const axiosDeduplicator = createAxiosDeduplicatorInstance(); const axiosInstance = axios.create(); axiosInstance.interceptors.request.use(axiosDeduplicator.requestInterceptor); axiosInstance.interceptors.response.use( axiosDeduplicator.responseInterceptorFulfilled, axiosDeduplicator.responseInterceptorRejected ); // Make two identical requests const url = 'https://api.example.com/data'; axiosInstance.get(url); axiosInstance.get(url); // This will be deduped, only one actual request sent.
Debug
Known issues
gotchaWhen using AxiosDeduplicator class directly, methods must be bound to the instance or called via instance.method.bind(instance).
fix
Use axiosDeduplicator.requestInterceptor.bind(axiosDeduplicator) or use the factory function.
affects: >=0.0.0
breakingThe 'repeatWindowMs' option semantics changed in v1.2.0: Now it ensures no duplicate request is made within the window, even if the first request has completed.
fix
For previous behavior (only dedup while first is pending), set repeatWindowMs to 0.
affects: >=1.2.0
gotchaThe skip function receives config, res, error in that order, but documentation says (config, error, res).
fix
Use function skip(config, res, error) as shown in the README, not the doc order.
affects: >=0.0.0
gotchaIf using TypeScript and AxiosRequestConfig, the plugin's headers may not be fully compatible with Axios types.
fix
Assert types as needed: (config as any).headers.
affects: >=0.0.0
Errors
Common errors & fixes
Cannot read properties of undefined (reading 'requestInterceptor')
Factory function not called correctly, or import failed.
fix
Ensure createAxiosDeduplicatorInstance() is called: const dedup = createAxiosDeduplicatorInstance();
this.requestInterceptor is not a function
Using class directly without binding methods.
fix
Bind methods: axiosDeduplicator.requestInterceptor.bind(axiosDeduplicator)
Uncaught (in promise) TypeError: axiosDeduplicator.responseInterceptorFulfilled is undefined
Factory returned undefined; likely missing return statement or incorrect configuration.
fix
Check that createAxiosDeduplicatorInstance returns an object with all three interceptors.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
axiosrequiredPeer dependency required; axios instance must be provided.
Agent activity
18 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
axios-deduplicator — npm install axios-deduplicator · libregistry