Fork
this is a fork of https://github.com/aishek/axios-rate-limit which has following changes in it:
- rewrite in Typescript
- allows passing in a custom store, to share the state between instances/servers.
Note: this module does not share state with other processes/servers by default. Use a redis or Memcached Store for shared states.
Stores
this fork uses the stores avaialble from express rate limiting. Therefore easy extendable :)
- Memory Store (default, built-in) - stores hits in-memory in the Node.js process. Does not share state with other servers or processes.
- Redis Store
- Memcached Store
axios-rate-limit
A rate limit for axios: set how many requests per interval should perform immediately, other will be delayed automatically.
Installing
yarn add axios-rate-limit
Usage
import axios from 'axios';
import rateLimit from 'axios-rate-limit';
const http = rateLimit(axios.create(), { maxRequests: 2, perMilliseconds: 1000, maxRPS: 2 })
http.getMaxRPS()
http.get('https://example.com/api/v1/users.json?page=1')
http.get('https://example.com/api/v1/users.json?page=2')
http.get('https://example.com/api/v1/users.json?page=3')
http.setMaxRPS(3)
http.getMaxRPS()
http.setRateLimitOptions({ maxRequests: 6, perMilliseconds: 150 })