Published
Edited
Nov 22, 2020
Insert cell
Insert cell
Insert cell
old_fetch("https://api.punkapi.com/v2/beers?")
Insert cell
Insert cell
beers = paginated_fetch`https://api.punkapi.com/v2/beers?page=${1}` // Provide the initial page number
Insert cell
Insert cell
function paginated_fetch(url, page, previousResponse = []) {
return fetch(`${url[0]}${page}${url[1]}`) // Insert the page number into the URL
.then(response => response.json())
.then(newResponse => {
const response = [...previousResponse, ...newResponse]; // Combine the two arrays

if (newResponse.length !== 0) {
page++;

return paginated_fetch(url, page, response);
}

return response;
});
}
Insert cell
Insert cell
taco_beers = paginated_fetch`https://api.punkapi.com/v2/beers?page=${1}&food=tacos`
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more