fetch with async and await
The same request written in a readable top-to-bottom style.
AJAX · fetch with async and awaitBeginner
async function loadItems() {
const response = await fetch('/api/items');
const data = await response.json();
return data.items;
}
loadItems().then(function (items) { console.log(items.length + ' items'); });fetchasyncawaitjson