My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Throttling Axios requests

Gokul N K's photo
Gokul N K
·Jun 15, 2018

I am using axios library for making API calls. The endpoint to which I am making the API calls has the following restrictions.

var rules = [
  {interval: 1, limit: 5},
  {interval: 3600, limit: 1000, precision: 100}
  ];

I am looking for a rate-limiting, throttling npm that can address this. I have explored rate-limit, quota and node-rate-limiter but they don't seem to get the task done.

npmjs.com/package/rate-limit allows only setting up delay between API calls. I don't want to do this.

npmjs.com/package/quota seems to be a ok ok solution. I will have to write a custom preset like github.com/analog-nico/quota/blob/HEAD/lib/..

github.com/jhurliman/node-rate-limiter seems to be interesting but again there is no way to handle two rules at the same time. If there was a way to reduce the tokens for two different limiters for every request made it could have been a perfect fit.

Considering that this is a general requirement I was assuming that there would be some standard way of doing this in node. Am I missing something very obvious.