Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Networking 3: DNS, HTTP and HTTPS

    Headers and Bodies

    Headers are the label: Name: value lines of metadata. Names are case-insensitive.

    Chapter 6 of 134 min read

    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: value lines of metadata. Names are case-insensitive.

    • The body is the contents — any bytes: JSON, HTML, an image, a PDF.

    • Content-Type says what the body is, as a MIME type (also called media type):

    MIME typeBody is…
    application/jsonJSON — the default for APIs
    text/html; charset=utf-8a web page, in UTF-8 (How Computers Work Ch 4.3)
    application/x-www-form-urlencodeda classic HTML form: name=Priya&age=21
    multipart/form-dataa form with file uploads
    image/png, application/pdfbinary files
    text/event-streama 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:

    JSON
    {
      "id": 42,
      "owner": "priya",
      "title": "Biology — Cells",
      "tags": ["exam", "chapter-3"],
      "pinned": false,
      "summary": null
    }
    • Objects { } of "key": value pairs; 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#

    HeaderDirectionPurpose
    Hostrequestwhich website (Ch 3)
    Content-Type / Content-Lengthbothwhat the body is / how long
    Acceptrequestwhich formats the client can handle
    Authorizationrequestcredentials, e.g. Bearer <token> (Authentication and Authorization (coming soon))
    User-Agentrequestwhich client software
    Cookie / Set-Cookierequest / responseCh 7
    Cache-Control, ETag, If-None-MatchbothCh 8
    Locationresponsewhere to go (redirects, 201 Created)
    Accept-Encoding / Content-Encodingbothcompression, e.g. gzip, br (Brotli) — JSON often shrinks 70–90%
    X-Request-IDbotha unique ID to trace one request through many services (Observability in Practice (coming soon))

    Check yourself

    4 questions
    1

    What does Content-Type: application/json tell the receiver?

    Show answer

    That the body is JSON text.

    2

    What's serialization?

    Show answer

    Turning in-memory data into a format (like JSON text) that can be sent or stored.

    3

    Which header carries a login token?

    Show answer

    Authorization (or a cookie).

    4

    Which content type do streaming AI chat responses often use?

    Show answer

    text/event-stream (server-sent events).