In order to avoid the "Error 429 Too Many Requests" error in browser, how can I modify the below code so that no more than 10 calls per second are made?
This 10 calls per second rate limit is imposed by a 3rd-party API, over which we have no control.
Thanks in advance!
// Array of hundreds of URLS
const urls = allNames.map(
(name) =>
`https://example.com/api/v3/results/${name}?limit=120&apikey=123`
);
// TODO add throttle so as to not exceed 10 calls per second
const getStaticProps = async () => {
Promise.allSettled(
urls.map((url) =>
fetch(url).then((resp) => resp.json())
)
).then(console.log);
};