Send asynchronous browser requests with fetch, XMLHttpRequest, JSON, errors, and progressive UI.
Lessons
Make a simple GET request with the fetch API.
fetch() Basics is easiest to learn by reading the example, changing it, and observing the result.
async function showLessons() {
const response = await fetch('/api/lessons');
const lessons = await response.json();
const list = document.querySelector('#list');
list.innerHTML = lessons
.map(lesson => `<li>${lesson.title}</li>`)
.join('');
}
showLessons();Practice the fetch() Basics example in a small scratch file, then explain what changed and why.