HTTP messages and APIs
Requests and responses
HTTP is a protocol for exchanging messages. A request identifies an intended action and target. A response communicates the result. An API (application programming interface) is an agreed interface used by software; a web API often uses HTTP. JSON is a text format for structured data, not a network protocol. A request to read note N1 might return a JSON object with its title.
Read the method and target
GET requests a representation of a resource; POST asks the resource to process the supplied content according to its own semantics. In Notes, GET /notes/N1 reads a note and POST /notes creates a note. These paths are fictional API design choices, not universal HTTP routes. GET is defined as safe in its intended semantics: a service should not use it for a requested state-changing action.
Interpret an illustrative response
Offline HTTP/1.1-style fields (not a complete wire message): GET /notes/N1 HTTP/1.1, Host: notes.example; response HTTP/1.1 200 OK, Content-Type: application/json, body {"title":"Reading list"}. The method and path identify the request; the status reports success; Content-Type describes the body format. HTTP/2 and HTTP/3 use different wire encodings but retain HTTP semantics.
Status codes describe results
In this API, 200 means a successful read, 201 means a resource was created, 400 indicates an invalid request, 401 indicates missing or invalid authentication credentials, 403 means the server refuses the request, and 404 means the resource was not found or the server does not disclose its existence. A 500 signals an unexpected server error. A status alone does not prove a security check was performed correctly.
Practice reading messages
A response to POST /notes has status 201 and Content-Type: application/json. What do you know? The API reports creation and describes the body as JSON. You still need the application policy and evidence to establish that the right user created the right record. Next, see how later requests can be associated with a session.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTTP messages and APIs — Knowledge check
Reason about fictional web application components and security decisions.
Which method suits reading a note without a requested state change?
A note is successfully created. Which status best expresses that?
What does Content-Type describe?
Which response can mean a resource existence is intentionally undisclosed?
What does 200 alone establish?