StoicBuilder

HandbookII the ForumRequest and response

IIthe Forum, The shape of an app

Request and response

1 min readUpdated 28 November

In plain words

A request is the envelope your app sends, with an address, a method, labels called headers and maybe a body; the response is the envelope that comes back.

Where you see it

Click any row in the Network tab. Headers shows the labels on both envelopes, Payload shows the body you sent, and Response shows exactly what the server returned.

src/lib/orders.tsbrowser
const res = await fetch("/api/orders", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ restaurantId: 7, items: [{ id: 12, quantity: 2 }] }),});const order = await res.json(); // the response body
Everything inside the braces is the request. res is the response.

What goes wrong

  1. Sending an object instead of JSON text

    A request body has to be text. Pass a plain object and fetch sends the words "[object Object]", so the server finds no items.

    body: { items: cart.items },
  2. Leaving out the Content-Type header

    Some servers, Express among them, only read the body as JSON when this header says so. The order arrives empty and the server complains that items are missing.

  3. Reading the response twice

    A response body can be read once. Calling res.json() after res.text() fails with "body stream already read".

What to tell your agent

Copy this into Lovable, Bolt, Cursor or any agent
For the request that's failing, show me the full request (method, address, headers, body) and the full response (status and body) side by side, then explain where they disagree.

Quick check

Sign in to earn +10 XP for it

The server says "items is required", but your code clearly sends items. What do you check?

Got a prompt that touches request and response?

Paste it. You get a better prompt first, then the cards that explain it.

Check your own prompt

Free, no sign-up.