The Plain Picture#
A parcel has a label (who it's for, what's inside, "fragile", "keep upright") and the contents. The label lets everyone handle it correctly without opening it.
The Real Names#
Headers are the label:
Name: valuelines of metadata. Names are case-insensitive.The body is the contents — any bytes: JSON, HTML, an image, a PDF.
Content-Typesays what the body is, as a MIME type (also called media type):
| MIME type | Body is… |
|---|---|
application/json | JSON — the default for APIs |
text/html; charset=utf-8 | a web page, in UTF-8 (How Computers Work Ch 4.3) |
application/x-www-form-urlencoded | a classic HTML form: name=Priya&age=21 |
multipart/form-data | a form with file uploads |
image/png, application/pdf | binary files |
text/event-stream | a stream of server-sent events — how AI chat answers stream word by word |
Under the Hood#
JSON — the format you'll use every day#
JSON (JavaScript Object Notation) is text that describes structured data:
{
"id": 42,
"owner": "priya",
"title": "Biology — Cells",
"tags": ["exam", "chapter-3"],
"pinned": false,
"summary": null
}Objects
{ }of"key": valuepairs; arrays[ ]; strings in double quotes; numbers;true/false;null.It's text, so it's always sent as UTF-8.
Turning your program's data into JSON text is serialization; reading JSON text back into data is deserialization (or parsing — How Computers Work Ch 9).
Headers you'll meet constantly#
| Header | Direction | Purpose |
|---|---|---|
Host | request | which website (Ch 3) |
Content-Type / Content-Length | both | what the body is / how long |
Accept | request | which formats the client can handle |
Authorization | request | credentials, e.g. Bearer <token> (Authentication and Authorization (coming soon)) |
User-Agent | request | which client software |
Cookie / Set-Cookie | request / response | Ch 7 |
Cache-Control, ETag, If-None-Match | both | Ch 8 |
Location | response | where to go (redirects, 201 Created) |
Accept-Encoding / Content-Encoding | both | compression, e.g. gzip, br (Brotli) — JSON often shrinks 70–90% |
X-Request-ID | both | a unique ID to trace one request through many services (Observability in Practice (coming soon)) |
Check yourself
4 questionsWhat does Content-Type: application/json tell the receiver?
Show answerHide answer
That the body is JSON text.
What's serialization?
Show answerHide answer
Turning in-memory data into a format (like JSON text) that can be sent or stored.
Which header carries a login token?
Show answerHide answer
Authorization (or a cookie).
Which content type do streaming AI chat responses often use?
Show answerHide answer
text/event-stream (server-sent events).