0

How can I write code to request lots of data from an API with a limit of 1 query per second? Should I use a loop and setTimeout?

The API I want to use has a limit of 1 query per second and I want to make quite a lot of requests (to analyse some data). I'm not sure how best to do this as it's the first time I'm attempting to do something like this. Ideally I'd like to query the data and send it to a database (I'm familiar with Mongo and SQL) but I don't mind any way to store the data I get back as I can add it to a database later. Any and all suggestions are welcome!

15th Aug 2020, 11:05 PM
Rhea
Rhea - avatar
7 Antworten
+ 2
first make sure that there are no other options. sometimes theres an endpoint where you can fetch a multiple data in single request. loop or setTimeout. i'll say setTimeout. it may have a fraction of inaccuracy but its simpler and enough get the job done.
15th Aug 2020, 11:44 PM
Taste
Taste - avatar
+ 2
Rhea Assuming you are using Nodejs, check this out https://code.sololearn.com/cfgu1kiaTO0Z/?ref=app
16th Aug 2020, 4:28 AM
Calviղ
Calviղ - avatar
0
Thanks Taste for your advice. I think I might have to use a loop and setTimeout to make requests for each item in a dataset, hopefully that is not a bad idea/mix
16th Aug 2020, 12:00 AM
Rhea
Rhea - avatar
0
try setInterval
16th Aug 2020, 12:05 AM
Taste
Taste - avatar
0
I'll give writing that code a go, thank you
16th Aug 2020, 12:08 AM
Rhea
Rhea - avatar
0
perhaps check of limit is server side job and you simply send request after receive answer and wait
16th Aug 2020, 5:00 AM
zemiak
0
I have a dataset and would need to send a request for each individual item. The API I want to use has a limit of 1 query per second
16th Aug 2020, 11:08 AM
Rhea
Rhea - avatar