Registry / devops / axios-throttler

axios-throttler

JSON →
library0.2.0jsnpmunverified

A lightweight request rate-limiter for axios implementing a leaky-bucket algorithm. Current version 0.2.0 (updated 2024) requires axios as a peer dependency (1.x). Differentiators: extremely small (37 lines), TypeScript-first, no runtime dependencies beyond axios. Allows throttling via requests per second (rps) or requests per minute (rpm) with a simple API. Works by adding an axios request interceptor. Maintained but still early stage.

npm install axios-throttler
INSTALL
IMPORT
SIG · AXIOS-THROTTLER
A
axios-throttler
devopsjavascriptv0.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.

AxiosThrottler
import { AxiosThrottler } from 'axios-throttler'
import axiosThrottler from 'axios-throttler'
ESM only; TypeScript types included. Default import is not supported.
AxiosThrottler.throttle
AxiosThrottler.throttle(client, AxiosThrottler.rps(5))
new AxiosThrottler().throttle(client, 5)
throttle is a static method; no instantiation needed.
AxiosThrottler.rps
AxiosThrottler.rps(5)
5
Must use factory methods rps or rpm to create options, not raw number.

Creates axios client, throttles to max 5 requests per second, then issues 5 concurrent requests.

import axios from 'axios'; import { AxiosThrottler } from 'axios-throttler'; const client = axios.create({ baseURL: 'https://api.example.com' }); AxiosThrottler.throttle(client, AxiosThrottler.rps(5)); async function fetchData() { const responses = await Promise.all([ client.get('/endpoint1'), client.get('/endpoint2'), client.get('/endpoint3'), client.get('/endpoint4'), client.get('/endpoint5'), ]); console.log(responses.map(r => r.status)); } fetchData();
Debug
Known issues
breakingAxios is now a peer-dependency. If you don't have axios installed, the package will not work.
fix
Ensure axios is installed: npm install axios
affects: >=0.2.0
deprecatedVersion 0.1.1 is deprecated; please upgrade to 0.2.0.
fix
Upgrade to 0.2.0: npm install axios-throttler@latest
affects: >=0.1.0 <0.2.0
gotchaThe throttler only works with axios instances created via axios.create(), not the global axios.
fix
Always create a client with axios.create() before throttling.
affects: >=0.1.0
gotchaThrottling uses request interceptors; response interceptors may not be preserved when applying throttle.
fix
Apply throttle after setting up all interceptors, or reapply them.
affects: >=0.1.0
gotchaThrottle rates are per instance, not shared across instances.
fix
Apply throttle separately for each axios client instance.
affects: >=0.1.0
Errors
Common errors & fixes
Cannot find module 'axios-throttler' or its corresponding type declarations.
Package not installed or TypeScript type resolution failing.
fix
Install the package: npm install axios-throttler. Also ensure tsconfig.json has 'moduleResolution': 'node' or 'node16'.
TypeError: AxiosThrottler.throttle is not a function
Attempting to call throttle before importing AxiosThrottler correctly.
fix
Import { AxiosThrottler } from 'axios-throttler' (named import, not default).
AxiosThrottler is not a constructor
Trying to instantiate AxiosThrottler with new keyword.
fix
Use static methods directly: AxiosThrottler.throttle(client, options) without new.
Invalid throttle option: expected rps or rpm object
Passing a number directly instead of using AxiosThrottler.rps() or AxiosThrottler.rpm().
fix
Use AxiosThrottler.rps(5) or AxiosThrottler.rpm(100).
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
axiosrequiredpeer dependency required for throttling (version 1.x)
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources