https://github.com/aishek/axios-rate-limit
Rate limit for axios
https://github.com/aishek/axios-rate-limit
axios js rate-limit rate-limiting rate-limits ratelimit ratelimiter ratelimiting typescript
Last synced: 5 months ago
JSON representation
Rate limit for axios
- Host: GitHub
- URL: https://github.com/aishek/axios-rate-limit
- Owner: aishek
- License: mit
- Created: 2019-04-20T19:05:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-07T14:47:33.000Z (about 1 year ago)
- Last Synced: 2025-04-19T10:40:42.423Z (6 months ago)
- Topics: axios, js, rate-limit, rate-limiting, rate-limits, ratelimit, ratelimiter, ratelimiting, typescript
- Language: JavaScript
- Homepage:
- Size: 246 KB
- Stars: 242
- Watchers: 2
- Forks: 35
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# axios-rate-limit
[](https://www.npmjs.com/package/axios-rate-limit)
[](https://www.npmjs.com/package/axios-rate-limit)
[](https://bundlephobia.com/package/axios-rate-limit@latest)
[](https://github.com/aishek/axios-rate-limit/actions?query=branch%3Amaster++)
[](https://coveralls.io/r/aishek/axios-rate-limit)
[](https://packagephobia.now.sh/result?p=axios-rate-limit)
[](https://snyk.io/test/npm/axios-rate-limit)A rate limit for [Axios](https://www.npmjs.com/package/axios): set how many requests per interval should perform immediately, other will be delayed automatically.
## Installing
```bash
npm install axios-rate-limit
```## Usage
```javascript
import axios from 'axios';
import rateLimit from 'axios-rate-limit';// sets max 2 requests per 1 second, other will be delayed
// note maxRPS is a shorthand for perMilliseconds: 1000, and it takes precedence
// if specified both with maxRequests and perMilliseconds
const http = rateLimit(axios.create(), { maxRequests: 2, perMilliseconds: 1000, maxRPS: 2 })
http.getMaxRPS() // 2
http.get('https://example.com/api/v1/users.json?page=1') // will perform immediately
http.get('https://example.com/api/v1/users.json?page=2') // will perform immediately
http.getQueue() // [{...}]
http.get('https://example.com/api/v1/users.json?page=3') // will perform after 1 second from the first one// options hot-reloading also available
http.setMaxRPS(3)
http.getMaxRPS() // 3
http.setRateLimitOptions({ maxRequests: 6, perMilliseconds: 150 }) // same options as constructor
```## Alternatives
Consider using Axios built-in [rate-limiting](https://www.npmjs.com/package/axios#user-content--rate-limiting) functionality.