Zero dependencies, fixed-window, queued rate limiter for Axios: set how many requests per interval should perform immediately, other will be delayed automatically.
npm install axios-rate-limitimport axios from 'axios';
import rateLimit from 'axios-rate-limit';
const http = rateLimit(axios.create(), {
limits: [
{ maxRequests: 5, duration: '2s' },
{ maxRequests: 2, duration: '500ms' }
]
})
http.get('https://example.com/api/v1/users.json?page=1')
http.getQueue()See source code for all available options.
- Single rate limit — API enforces one limit; use one window via
limits. - Multiple rate limits — API enforces several limits (e.g. per second and per minute); use multiple windows.
- Custom queue — Pass your own queue (e.g. to log when requests are added or removed).
- Mocking in Jest — How to mock axios-rate-limit in Jest so tests do not hit the network (see issue #51).
Consider using Axios built-in rate-limiting functionality.