Send asynchronous browser requests with fetch, XMLHttpRequest, JSON, errors, and progressive UI.
Lessons
Chain promises for sequential request steps.
Promises and .then() is easiest to learn by reading the example, changing it, and observing the result.
fetch('/api/lessons')
.then(response => {
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return response.json();
})
.then(lessons => console.log(lessons))
.catch(error => console.error(error.message))
.finally(() => console.log('Request complete'));Practice the Promises and .then() example in a small scratch file, then explain what changed and why.