Async – await using axios

var t= new Date; var timeStr = t.toUTCString();
function getCoffee() {
return newPromise(resolve=> {
setTimeout(() =>resolve(‘☕ mocha coffeee’), 2000); // it takes 2 seconds to make coffee
});
}
asyncfunctiongo() {
try {
// but first, coffee
const coffee = await getCoffee();
console.log(coffee); // ☕
document.getElementById(‘asyncTest’).innerHTML = coffee;
// then we grab some data over an Ajax request
constwes = await axios(‘https://api.github.com/users/wesbos’);
console.log(wes.data); // mediocre code
const footerData = await axios({ url:footerLinks, method:’GET’, responseType:’json’ });
console.log(footerData.data); // mediocre code
var totalString = ‘ ONE : ‘;
for (vari = 0; i

totalString = totalString + tagContent;
}
document.getElementById(‘sectionNormal’).innerHTML = totalString;
} catch (e) {
console.error(e);
}
}
go();
<body>
<h1>Bismillah ar Rehmaan nir Raheem</h1>
<hr />
<hr />
</body>
Advertisements