HTTP requests, representations, and caching
- •
- •
Clients
- •
browsers, command-line tools, mobile applications, backend services, and other programs can act as HTTP clients.
- •
- •
Typical navigation
- •
interpret the URL; reuse a suitable cahce response or connection where possible; resolve the hostname when needed; exchange a request and response. the application processes it, and a browser may request furtehr resources
- •
- •
Protocol and browser behavior
- •
HTTP/1.1 message examples show a textual wire format; HTTP/2 and HTTP/3 use different framing.
- •
Browser rendering is applictaion behavior build on top of HTTP
- •
- •
Messages
- •
a request identifies a method, target, and protocol version; it may carry headers and a body.
- •
a response carries a status code, headers, and sometimes a body.
- •
headers carry metadata such as content type, accepted formats, cache policy, authentication, and connection details.
- •
Body → contains representation data and is not necessarily HTML.
- •
{{renderer :bermaid}}
- •
sequenceDiagram autonumber participant Client as Client Browser/App participant Server as Server Backend Note over Client,Server: 1. First request - no cache Client->>Server: GET /api/v1/users/101 Note over Client,Server: Headers: Host, Accept, User-Agent Note over Client,Server: Body: empty Note over Server: Fetch data, generate ETag "a8f3-v1" Server-->>Client: 200 OK Note over Client,Server: Content-Type: application/json Note over Client,Server: ETag: "a8f3-v1" Note over Client,Server: Body: JSON id 101, name Alice Note over Client,Server: 2. Second request - ETag revalidation Client->>Server: GET /api/v1/users/101 Note over Client,Server: If-None-Match: "a8f3-v1" Note over Server: ETag matches, data unchanged Server-->>Client: 304 Not Modified Note over Client,Server: ETag: "a8f3-v1" Note over Client,Server: Body: empty, use local cache - •
- •
- •
- •
Methods
- •
GET retrieves a representation and is intended to be safe.
- •
HEAD asks for response metadata without the representation body.
- •
POST commonly submits data or requests processing.
- •
PUT commonly replaces a resource representation; PATCH applies a partial change; DELETE requests removal.
- •
safety and idempotence describe intended semantics, not a guarantee that every server implementation is correct.
- •
- •
- •
Testing
- •
curl makes requests and inspects responses; the practicum varies methods and header.
curl -iincludes response headers;curl -Imakes a HEAD request
- •
- •
- •
- •
- •
- •
