Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
matrix:
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [16, 18, 20, 22, 24, 25, 26]
node-version: [20, 22, 24, 25]
# See supported Axios versions at https://www.npmjs.com/package/axios?activeTab=versions
axios-version: [0, 1]
env:
Expand Down
10 changes: 10 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# axios-rate-limit

## Testing instructions
- Run `npm test` to run tests
- Run `npm run lint` to run linter

## Fix issue instructions
- Create regression tests first if possible
- Run the regression tests before making any code changes to ensure it fails without fix
- Fix any test or lint errors until the whole suite is green.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Change Log
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
* Multiple rate limits via optional `limits` array (see https://github.com/aishek/axios-rate-limit/issues/55). Each entry is `{ maxRequests, duration }`; `duration` is a string with numeric value + unit: `ms`, `s`, `m`, `h` (e.g. `'1s'`, `'2m'`). A request is sent only when every window allows one more; each window resets independently after its time. Invalid `duration` throws with a message hinting at valid formats.
* Backward compatibility: if `limits` is not provided, behavior is unchanged (single limit via `maxRequests` + `perMilliseconds` or `maxRPS`). Legacy options `perMilliseconds`, `maxRPS` and existing single-limit API remain supported; `getMaxRPS` / `setMaxRPS` / `setRateLimitOptions` work as before in that mode.

## 1.4.0
* Expose requests queue via getQueue (see https://github.com/aishek/axios-rate-limit/pull/62)

Expand Down
25 changes: 13 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,21 @@ npm install axios-rate-limit
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
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()

// options hot-reloading (same options as constructor)
http.setMaxRPS(3)
http.getMaxRPS() // 3
http.setRateLimitOptions({ maxRequests: 6, perMilliseconds: 150 }) // same options as constructor
http.setRateLimitOptions({ maxRequests: 6, perMilliseconds: 150 })
http.setRateLimitOptions({ maxRequests: 10, duration: '1s' })
http.setRateLimitOptions({ limits: [{ maxRequests: 3, duration: '1s' }, { maxRequests: 1, duration: '200ms' }] })
```

## Tech Details
Expand Down
Loading