title: Limiting Axios outgoing requests to an external API (Rate Limiting)
body: <p>I am working with several APIs on my app and a few of them have limits that are not just simply per sec.
  For example one of my apis has the following limits:</p>
  <pre><code>Max 100 requests per 2 minutes
  Max 20 requests per 1 second
  </code></pre>
  <p>So I have tried implementing this library <a href="https://github.com/aishek/axios-rate-limit" rel="nofollow noreferrer">https://github.com/aishek/axios-rate-limit</a> in the following way:</p>
  <pre><code>axiosRateLimit(baseAxios.create(), {
    maxRequests: 1, // 1
    perMilliseconds: 1200 // per 1.2 seconds
    // 100 requests per 2 minutes, 50 requests per 60 seconds, 60 seconds / 50 requests = 1 per 1.2 seconds
  });
  </code></pre>
  <p>But it can't take advantage of the <code>20 requests per 1 second</code> limit, because to adhere to the <code>100 requests per 2 minutes</code>, I have to limit it to <code>1 per 1.2 seconds</code>, otherwise if I limit it to <code>20 per second</code>, I can do <code>2400 requests in 2 minutes</code>.</p>
  <p>So how can I implement both conditions and have them both working together?
  What if I need to do only <code>50 requests every 2 minutes</code>, with the current implementation, it will take me <code>1 minute</code> for all of them, and I am not taking advantage of the <code>20 per second</code> (becaus if I do, I can do it in <code>3 seconds</code>, instead of <code>1 minute</code>).</p>
  <p>Is there a way to accomplish this with this library? Initially I thought that the <code>maxRequests</code> works with <code>perMilliseconds</code> and <code>maxRPS</code> can be used to handle the other case, so when all 3 are supplied I thought it would be like:</p>
  <pre><code>{
    maxRequests: 100, // 100 max requests
    perMilliseconds: 2 * 60 * 1000, // per 2 minutes
    maxRPS: 20 // 20 max per second
  }
  </code></pre>
  <p>But the docs say:</p>
  <pre><code>// 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 })
  </code></pre>
  <p>So obviously it doesnt work the way I expected it to work, is there a way to achieve what I want?</p>
  <p>Are there any other libraries that can do what I want?</p>
  <p>Do I have to implement it from scratch on my own?</p>