Last active
November 8, 2021 21:08
-
-
Save clicktechnology/740b77492f2c027ac2a2a766bc93f812 to your computer and use it in GitHub Desktop.
JavaScript / NodeJS - Fetch using Async / await
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 fetchPokemon = async (id) => { | |
try { | |
const res = await fetch(`https://pokeapi.co/api/v2/pokemon/${id}`); | |
const data = await res.json() | |
console.log('LOL', data, data.name) | |
console.log(res.status) // get the html code too, check for 200 or 404/500 etc. | |
} catch(err) { | |
console.error(err) | |
} finally { | |
console.log('I will always run no matter what.') | |
} | |
} | |
fetchPokemon(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment