Skip to content

Instantly share code, notes, and snippets.

@kkroesch
Created June 13, 2021 14:49
Show Gist options
  • Save kkroesch/a26e648ab489a84756c09853975bdd05 to your computer and use it in GitHub Desktop.
Save kkroesch/a26e648ab489a84756c09853975bdd05 to your computer and use it in GitHub Desktop.
Load JSON data with async/await
let results;
const DEBUG = true;
const load_data = async () => {
try {
const url = "https://httpbin.org/json"
const response = await fetch(url)
results = await response.json()
if (DEBUG) console.log(response.ok)
if (DEBUG) console.log(results.slideshow)
} catch (error) {
if (DEBUG) console.error(error.message)
}
}
load_data()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment