Skip to content
Discussion options

You must be logged in to vote

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:

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

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sindresorhus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants