Skip to content

Instantly share code, notes, and snippets.

@ilearnjavascript
Created March 28, 2019 23:07
Show Gist options
  • Save ilearnjavascript/21cc7dbb76a3da2fbd756ed9414fe559 to your computer and use it in GitHub Desktop.
Save ilearnjavascript/21cc7dbb76a3da2fbd756ed9414fe559 to your computer and use it in GitHub Desktop.
async await api call
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