Created
April 12, 2020 16:23
-
-
Save newmedia2/3bc111f73ea79cca6ea17eeffcac2cc4 to your computer and use it in GitHub Desktop.
Fetch API with async/await
This file contains hidden or 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 getGithubUser = async user => { | |
const url = `https://api.github.com/users/${user}`; | |
try { | |
const response = await fetch(url); | |
return await response.json(); | |
} catch(exception) { | |
throw `Something went wrong when fetching from ${url}: \n\n ${exception}`; | |
} | |
} | |
getGithubUser('newmedia2') | |
.then(user => console.log(user)) | |
.catch(err => console.log(err)); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment