Skip to content

Instantly share code, notes, and snippets.

@sillyslux
Created October 22, 2020 15:28
Show Gist options
  • Save sillyslux/f94351533fc287d140ec07e6f2233a3b to your computer and use it in GitHub Desktop.
Save sillyslux/f94351533fc287d140ec07e6f2233a3b to your computer and use it in GitHub Desktop.
try here https://swapi.dev/ with your browser console
async function getAll () {
let cont = true;
let page = 1;
let ret = [];
while(cont) {
const moreShips = await fetch("https://swapi.dev/api/starships/?page="+page).then(r => r.json());
if (!moreShips.next) cont = false;
page = page + 1;
ret = [...ret, moreShips];
}
return ret;
}
getAll().then(console.log)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment