async fetch example

PHOTO EMBED

Wed Mar 17 2021 09:51:08 GMT+0000 (Coordinated Universal Time)

Saved by @danisalsas #javascript

// Async function example:
async function getCurrencies() {
  // Use fetch to get data from API
  // and assign it to a variable:
  const data = await fetch('https://currencyapi.net/api/v1/rates?key=7zq3xkh2qeZcnvFhfyDyFlvqx4EmQ7R3N1qq')
  // Convert the response to JSON
  // and assign it to a variable:
  const json = await data.json()

  // Log the JSON to console:
  console.log(json)
}
content_copyCOPY

https://blog.alexdevero.com/javascript-es2017-features