Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel:
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill:
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
return data;
// trigger async function
// log response or catch error of fetch promise
.then(data => console.log(data))
.catch(reason => console.log(reason.message))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment