I have to get all data from API that supports offset and limit, but i don't know the count or max offset.
i use while true and break the loop when a call returns no data
let flag = true;
let query_obj = {limit : 10, offset: 0};
while (flag) {
const data = await axios.get('https://domain.ex/path?limit=' + query_obj.limit + 'offset=' + query_obj.offset);
query_obj.offset += query_obj.limit;
if(data.items.length === 0){
flag = false;
}
}
I'm looking for best practice, so i think while loop and await inside a loop is not the best.
I'm trying to think about a solution using promise.all or RXJS, do you have any suggestions
Thanks