Created
February 23, 2020 02:25
-
-
Save ethanny2/9fc48802d08eba382a96e555ceb3b950 to your computer and use it in GitHub Desktop.
Handle asynchronous HTTP promises synchronously with async/await. Example using Pokemon API (https://pokeapi.co/)
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
let urlBase = "https://pokeapi.co/api/v2/pokemon/" | |
const sampleGet = async (pokemonName) => { | |
let response = await fetch(urlBase + pokemonName); | |
let parsedJson = await response.json(); | |
document.body.innerHTML = `<img alt="default front sprite for starmie" src=${parsedJson.sprites.front_default} >`; | |
} | |
sampleGet("starmie"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment