HTTP Requests and Responses
What this concept is
HTTP is an application protocol built around requests and responses. A request includes a method and target; a response includes a status and headers, and may include a body. The body is bytes until interpreted using a format and encoding.
Why it matters here
An API client needs more than the printed body. A JSON-looking error is still an error if the status says the requested operation did not succeed.
Concrete example
A conceptual exchange is:
GET /sessions HTTP/1.1
Host: 127.0.0.1:PORT
HTTP/1.0 200 OK
Content-Type: application/json
{"sessions":[25,15,25]}
This is a teaching sketch, not a complete packet capture. The standard-library fixture uses HTTP/1.0 responses by default; the client can send HTTP/1.1. Header fields describe interpretation; the body supplies the data. A 404 or 503 response can also contain JSON, so body parsing alone cannot establish success.
Common confusion / misconception
GET is intended to retrieve a representation; methods such as POST have different semantics. Do not infer safety from a friendly endpoint name. HTTP status categories are broad signals, not a complete application contract. A generally successful 204 response still lacks the body required by our endpoint.
How to use it
For each exchange record method, path, status, media type and a bounded body excerpt. Predict before running. Accept only the statuses the endpoint contract permits. Keep a human explanation of status separate from the numeric value used in the client; reason phrases are not a robust machine interface.
Check yourself
Can a 200 response contain an HTML error page? Yes. A proxy or application can return unexpected content; you still need media-type and schema checks.
Mini drill or application
Inspect /sessions, /missing and /unavailable using the supplied client adapter. Identify which fields changed and which layer made the decision. Explain why retrying 404 blindly would not repair a mistyped path.
Read this only if stuck
MDN HTTP overview explains the message model. This local exercise is deliberately smaller than the full protocol.