fetch then async code example
Example 1: async fetch api call
async function getUserAsync(name) {
try{
let response = await fetch(`https://api.github.com/users/${name}`);
return await response.json();
}catch(err){
console.error(err);
// Handle errors here
}
}
Example 2: javascript async fetch file html
async function () {
element.innerHTML = await (await fetch('./filetofetch.html')).text();
}