Skip to content

Instantly share code, notes, and snippets.

@jferreira-godaddy
Created August 21, 2017 14:44
Show Gist options
  • Save jferreira-godaddy/9a66a0180f3b39e706085a2b6aebd0a0 to your computer and use it in GitHub Desktop.
Save jferreira-godaddy/9a66a0180f3b39e706085a2b6aebd0a0 to your computer and use it in GitHub Desktop.
Fetch some JSON with async function
async function fetchJson(url) {
try {
const request = await fetch(url);
const text = await request.text();
return JSON.parse(text);
}
catch (error) {
console.log(`ERROR: ${error.stack}`);
}
}
// Can be called with:
// fetchJson('https://example.com/file.json')
// .then(obj => console.log(obj));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment