Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hokify/axios-rate-limit

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hokify/axios-rate-limit

Rate limit for axios.

  • 2.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.1K
increased by495.96%
Maintainers
1
Weekly downloads
 
Created
Source

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

npm version npm downloads Build Status

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';

// 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

Keywords

FAQs

Package last updated on 03 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc