Created
September 22, 2019 10:18
-
-
Save burnjohn/20f8e97085e3ea5ffe82a236663c531f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetchPokemons = (url) => { | |
return fetch(url).then(response => response.json()); | |
}; | |
// Async example | |
(async () => { | |
const pokemon1 = await fetchPokemons('https://pokeapi.co/api/v2/pokemon/1'); | |
console.log(pokemon1); | |
const pokemon2 = await fetchPokemons('https://pokeapi.co/api/v2/pokemon/10'); | |
console.log(pokemon2); | |
const pokemon3 = await fetchPokemons('https://pokeapi.co/api/v2/pokemon/25'); | |
console.log(pokemon3); | |
})(); | |
// Promise.then example | |
fetchPokemons('https://pokeapi.co/api/v2/pokemon/1') | |
.then(pokemon1 => { | |
console.log(pokemon1); | |
return fetchPokemons('https://pokeapi.co/api/v2/pokemon/10'); | |
}) | |
.then(pokemon2 => { | |
console.log(pokemon2); | |
return fetchPokemons('https://pokeapi.co/api/v2/pokemon/25'); | |
}) | |
.then(pokemon3 => { | |
console.log(pokemon3); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment