function paginated_fetch(
url = is_required("url"),
page = 1,
previousResponse = []
) {
return fetch(`${url}&page=${page}`)
.then(response => response.json())
.then(newResponse => {
const response = [...previousResponse, ...newResponse];
if (newResponse.length !== 0) {
page++;
return paginated_fetch(url, page, response);
}
return response;
});
}