Created
March 28, 2019 23:07
-
-
Save ilearnjavascript/21cc7dbb76a3da2fbd756ed9414fe559 to your computer and use it in GitHub Desktop.
async await api call
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
async function getJoke() { | |
let url = 'https://api.icndb.com/jokes/random'; | |
let result = await (await fetch(url)).json(); | |
return result; | |
} | |
async function initApiCall() { | |
try { | |
let data = await getJoke(); | |
console.log(data.value.joke) | |
} | |
catch (err) { | |
console.error(`ERROR(${err.code}): ${err.message}`); | |
} | |
} | |
initApiCall(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment