Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

axios-rate-limit

aishek469.9kMIT1.4.0TypeScript support: included

Rate limit for axios.

axios, rate, limit

readme

axios-rate-limit

npm version npm downloads npm bundle size build status code coverage install size known vulnerabilities

A rate limit for Axios: set how many requests per interval should perform immediately, other will be delayed automatically.

Installing

npm install axios-rate-limit

Usage

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.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 functionality.

changelog

Change Log

This project adheres to Semantic Versioning.

1.4.0

1.3.3

  • Fix axios dependency specification

1.3.2

1.3.1

1.3.0

1.2.1

1.2.0

  • Add maxRPS options, getMaxRPS, setMaxRPS, setRateLimitOptions methods

1.1.3

1.1.2

1.1.1

1.1.0

1.0.1

1.0.0

0.0.4

0.0.3

  • Add jsdoc.

0.0.2

  • Fix default import.

0.0.1

  • Initial release.