Fetching all the records from a multi page API endpoint without recursion back to the same function. Example in JavaScript.
const getAllProducts = async () => {
// data and options is set elsewhere in this case
data['maxRecords'] = 250;
let res;
let products = [];
let page = 1;
do {
res = await axios.post(url, data, options);
products = [...products, ...res.data.pageRecords];
count = res.data.pageRecords.length;
data['page'] = page + 1;
} while (count === data['maxRecords'])
return products;
}