Make the web make sense
Module 3 / Lesson 3

Follow a Save request

Trace the browser → API → database → response path.

18 minutes

The browser asks

A user clicks Save. The browser sends an HTTP request with a method, URL and body. A server validates the request, identifies the user, checks permission and performs the write. It then returns a status and response body.

Render the actual outcome

Show a saving state while waiting. Confirm success only after the server reports the write succeeded. If the request fails, preserve the input and offer a retry. A click and a successful save are different events.

javascript
async function saveProgress(lessonId) {
  const response = await fetch("/api/progress", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ lessonId, completed: true })
  });
  if (!response.ok) throw new Error("Progress could not be saved");
  return response.json();
}