Answers for "js async fetch await get method"

17

async function fetchJson

async function getUserAsync(name) 
{
  let response = await fetch(`https://api.github.com/users/${name}`);
  let data = await response.json()
  return data;
}

getUserAsync('yourUsernameHere')
  .then(data => console.log(data));
Posted by: Guest on February-16-2020
0

how to Fetch API to Get Data using async await and then catch in javascript

// how to Fetch API to Get Data using async await and then catch in javascript
async function getFetchData(url){
    await fetch(url)
    .then(response => response.json())
    .then(data => console.log(`Id: ${data[99].id}, Title: ${data[99].title}`))
    .catch(error => console.log(error))
}
getFetchData(apiUrl);
Posted by: Guest on December-16-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language