Lesson 7 of 18
3. Client and Server

3.6 What goes in the headers and what goes in the body?

3 min read+10 XP

In the restaurant: The order slip has a top part (table number, "allergic to peanuts", "pay by card") and the order itself. The top part tells the kitchen how to handle the order; the order says what you want.

In the system:

  • Headers are labels about the message: who it's for, what format, how big, who's asking, how long it can be cached.
  • The body is the content itself: the JSON for a new cart item, the HTML of a page, an image.

Headers you'll meet again in this book:

HeaderWhat it saysChapter
HostWhich website this is for (one server can host many)here
Content-TypeThe format of the body, e.g. application/jsonhere
AuthorizationWho you are, e.g. a token3.11, 24
Cookie / Set-CookieSmall values the browser stores and sends back3.11
Cache-ControlWhether and how long the response can be cached13, 26
Retry-AfterWhen to try again (with 429 or 503)25

A GET usually has no body: everything needed is in the path and headers. A POST usually has one.

Memory code: "Headers describe, body delivers."