I'm building an app in nodeJS, express and MySQL where I'm collecting data from several different API:s using node fetch, one which has a limit of 200 calls per 5 minute.
In order to update my database completely I need to essentially run calls to this API nonstop, currently I'm trying to stay within the boundaries of the limit by using a sleep in a for loop/foreach.
The problem is that each request can vary in time and it just seems like I could make the calls more effective rather than constantly sleeping the same amount of time for each request. I was wondering if there's a better way to do this? I've been thinking about making e.g 199 calls async and then waiting exactly 5 minutes, and then repeating it.. but I have no idea how.
Couldn't find a thread on this but please do link one if there's a good answer already. Answers are much appreciated, and if you have other feedback please do let me know!
for (let i = 1; i < length; i++) {
try {
let id = IdCollection[i];
let resultFromApiCall = await datafetcher.MakeApiCall(id);
await sleep(2000);
} catch (error) {
console.log("Error in api-calls" + error);
}
}```
fetchor not, because I don't know what you're fetching.