Rate limit #2285
-
|
Hi, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
There is no built-in rate limiting as there are simply too many variations of rate limiting. To achieve it, you could make a plugin. You can also easily implement it using import PQueue from 'p-queue';
import got from 'got';
// Limit to 30 requests per minute
const queue = new PQueue({
intervalCap: 30,
interval: 60000, // 60 seconds
concurrency: 30 // Optional: control concurrent requests
});
// Wrap your got calls in queue.add()
async function makeRequest(url) {
return queue.add(() => got(url).json());
}
// Use it
const results = await Promise.all([
makeRequest('https://api.example.com/1'),
makeRequest('https://api.example.com/2'),
makeRequest('https://api.example.com/3')
// ... add as many as you want
]);This will automatically delay excess requests instead of canceling them, which is exacty what you're looking for. The queue handles all the timing logic for you, so you don't have to worry about implementing the rate limiting yourself. |
Beta Was this translation helpful? Give feedback.
There is no built-in rate limiting as there are simply too many variations of rate limiting. To achieve it, you could make a plugin.
You can also easily implement it using
p-queue: