Stop 01 · Internet & Backend BasicsTopics · 5/15

Request-Response Cycle

Part of the Backend Developer Roadmap

In short

Between a request arriving and a response leaving, your server does a lot: parse, check, route, query, format. When an API is slow or wrong, the bug lives in one of those steps.

The full round trip of a client sending an HTTP request to a server and receiving a response — every backend endpoint you'll ever build exists to handle one of these.

The mascot walks with a folder past a row of office counters, from a token machine to an officer's desk.

Think of it like this

A visit to the passport office

You take a token, one clerk checks your documents, another takes your photo, an officer approves, and you leave with a receipt. Miss a counter and you're sent back. A request walks through your server's counters the same way, in a fixed order.

Watch it happen

Inside the server: POST /orders

Connection
Parse
Middleware
Router
Handler + DB
Response

1/6A TCP connection arrives on port 3000 carrying POST /orders, some headers and a JSON body.

The big ideas

What you need to know

Order matters

Middleware and routes run top to bottom in the order you register them. Put body parsing and auth first.

One response per request

Every request must get exactly one response. Forget to send one and the client waits until it times out.

Errors jump the queue

When something throws, Express skips the remaining steps and goes straight to your error handler.

Measure every step

Logging the time per request shows you where slowness lives: your code, the database or a third-party API.

See it in code

Walk through the code

js
1import express from "express";2const app = express();3app.use(express.json());4 5app.use((req, res, next) => {6  const start = Date.now();7  res.on("finish", () => {8    console.log(req.method, req.url, res.statusCode, Date.now() - start + "ms");9  });10  next();11});12 13app.post("/orders", (req, res) => {14  if (!req.body?.item) return res.status(400).json({ error: "item is required" });15  res.status(201).json({ id: 42, item: req.body.item });16});

1/3Parse JSON bodies before any route needs req.body.

res.on("finish") fires after the response is fully sent, so the log shows the real total time. Test it with curl -X POST, a JSON body and the Content-Type header.

Save yourself the pain

Common mistakes

Oops

Calling res.json() twice, or calling next() after already sending a response.

Do this instead

Send exactly one response. Write return res.status(...).json(...) so the function stops right there.

Oops

Registering express.json() after your routes.

Do this instead

Middleware only applies to routes registered after it, so put body parsing near the top.

Your mission

Time every request

~20 min

Quick check

Your auth middleware is registered after app.get("/admin"). What happens to GET /admin?

Go deeper

  1. 1Use `curl` or Postman to manually send a request and inspect the raw response.
  2. 2Learn the anatomy of a request: method, URL, headers, body.
  3. 3Trace what a server does internally between receiving a request and sending a response.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge