Skip to content

Instantly share code, notes, and snippets.

View JuanmaMenendez's full-sized avatar

Juan M Menendez JuanmaMenendez

View GitHub Profile
@JuanmaMenendez
JuanmaMenendez / es7-async-await.js
Created December 3, 2018 20:28
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved