Skip to the workspace
Pebellslearn by building
How a Full-Stack App Fits Together  ›  Lesson

The Round Trip: Browser to Database and Back

JavaScript 14 minA request travels from a browser event through the network, the server's routing, identity check and handler, down to the database and back as JSON that the client renders, and debugging means finding the first hop where the data goes wrong.

full stack / The Round Trip: Browser to Database and Back

Explore each scene at your own pace.

01 · The rule

The rule

The Round Trip: Browser to Database and Back

Open Sprout's "My plants" screen and a list appears in a fraction of a second. In that time a request crosses the internet, runs your server code, questions the database and travels all the way back. When something goes wrong, knowing each hop tells you exactly where to look.

The rule

Out through the server, down to the data, back as JSON, onto the screen.

Here is the whole trip for Sprout's plant list:

  1. Trigger. The screen appears and its JavaScript calls fetch('/api/plants').
  2. Network. The browser finds the server's address (DNS), opens a secure connection (TLS) and sends the request, with the user's login cookie attached.
  3. Routing. The server matches the method and path, GET /api/plants, to a handler function.
  4. Identity. Before the handler, a check reads the cookie and works out which user is asking.
  5. Query. The handler asks the database for that user's plants.
  6. Rows to JSON. The database returns rows. The server turns them into JSON and picks a status code.
  7. Response. The answer travels back over the same connection.
  8. Render. JavaScript parses the JSON, stores it and redraws the list.

What actually crosses the network is plain text:

GET /api/plants HTTP/1.1
Host: sprout.example.com
Cookie: token=eyJhbGciOi...
HTTP/1.1 200 OK
Content-Type: application/json

[{"id": 7, "name": "Fern", "water_every_days": 3, "last_watered": "2026-09-24"}]

Notice that each layer only speaks to its neighbour. The browser never sees SQL, and the database never sees HTTP. The server is the translator between the two.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.