Send asynchronous browser requests with fetch, XMLHttpRequest, JSON, errors, and progressive UI.
Lessons
Work with RESTful resources over AJAX.
Consuming REST APIs is easiest to learn by reading the example, changing it, and observing the result.
const BASE = 'https://api.example.com';
export const api = {
list: () => fetch(`${BASE}/lessons`).then(r => r.json()),
get: (id) => fetch(`${BASE}/lessons/${id}`).then(r => r.json()),
create: (data) => fetch(`${BASE}/lessons`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
}).then(r => r.json())
};Practice the Consuming REST APIs example in a small scratch file, then explain what changed and why.