The basic model
A client sends a request; a server sends one response. A browser is a client, but so are mobile apps, command-line tools and other servers. A resource might be an HTML document, image, API result or an action rather than a literal file.
HTTP is an application-layer protocol. HTTP/1.1 and HTTP/2 normally use TCP; HTTP/3 uses QUIC over UDP. HTTPS means HTTP is carried inside TLS, adding encryption, integrity and server authentication.
HTTP itself is stateless: each request contains the information needed to understand it. Applications create continuity with cookies, authorisation tokens, URLs and server-side sessions.
Anatomy of a URL
- Scheme chooses the protocol and security expectations: usually
https. - Host identifies the service and is resolved through DNS.
- Port identifies the receiving service; omitted defaults are 443 for HTTPS and 80 for HTTP.
- Path identifies a resource within that service.
- Query supplies parameters. Its format is application-defined.
- Fragment selects something within the returned representation. The browser uses it; it is not sent in an HTTP request.
Reserved or unsafe characters are percent-encoded as their bytes—for example a space is commonly represented as %20.
Requests and responses
In HTTP/1.1 a message is readable text headers followed, when present, by a body. The empty line separates headers from the body.
HTTP/2 and HTTP/3 encode the same concepts as binary frames rather than lines of text. The method, target, status, headers and body still have equivalent meaning.
Methods: what the client wants
| Method | Intent | Important property |
|---|---|---|
| GET | Retrieve a representation | Safe and idempotent; normally no request body semantics |
| HEAD | GET’s headers without its response body | Useful for metadata checks |
| POST | Submit data or start processing | Meaning comes from the target; not generally idempotent |
| PUT | Create or replace the target state | Idempotent |
| PATCH | Apply a partial change | Format defines the patch; not always idempotent |
| DELETE | Request removal of the target | Idempotent in intended effect |
| OPTIONS | Discover communication options | Used in CORS preflight requests |
| CONNECT | Create a tunnel | Commonly used through proxies |
Safe means the method is intended only to read. Idempotent means repeating the same request has the same intended effect as sending it once. A server can still log a GET, and two identical PUT responses need not be byte-for-byte identical.
Status codes: what happened
The first digit groups the result. The exact code is more useful than the broad class.
Informational
Interim progress, such as 100 Continue.
Successful
200 OK, 201 Created, 204 No Content.
Redirection
301/308 permanent, 302/307 temporary, 304 cache reuse.
Client-side issue
400 Bad Request, 401 needs authentication, 403 refused, 404 absent, 429 too many requests.
Server-side failure
500 internal error, 502 bad upstream response, 503 unavailable, 504 upstream timeout.
A 4xx does not necessarily mean buggy client software; it means the request cannot be fulfilled as sent. A 502 or 504 usually comes from a gateway or proxy speaking to another server.
Headers, representations and bodies
Headers carry metadata and control information. They are case-insensitive by name. A body carries the selected representation or submitted data.
| Header | Purpose |
|---|---|
| Host / :authority | Selects the site on a server hosting many names |
| Content-Type | Describes the body’s media type, such as application/json |
| Content-Length | Gives the body length in bytes when known this way |
| Accept | States response formats the client can use |
| Accept-Encoding | Offers compression such as gzip or Brotli |
| Authorization | Carries credentials for the request |
| Location | Points to a redirect target or newly created resource |
| Origin | Identifies the requesting web origin for CORS/security decisions |
| Vary | Tells caches which request headers change the response |
Content negotiation lets one URL have different representations—for example JSON versus HTML or English versus French. The response’s Content-Type says what was actually chosen.
Cookies, sessions and state
A server creates a cookie with Set-Cookie. The browser stores it and sends it in later matching requests using the Cookie header. Often the value is an opaque session identifier; the meaningful session data remains on the server.
- Secure restricts sending to secure connections.
- HttpOnly prevents page JavaScript from reading the cookie, reducing some theft risk.
- SameSite controls cross-site sending and helps defend against CSRF.
- Domain and Path define where it applies.
- Max-Age or Expires makes it persistent; otherwise it is a session cookie.
Cookies are not automatically private values: unless protected appropriately, they travel with every matching request and can be changed by the client. Servers must validate them, use TLS, and protect sensitive session identifiers.
HTTP caching
Caching avoids transferring a representation again when a stored copy is fresh or still valid. Browsers, shared proxies and CDNs can all cache, subject to directives.
Cache-Control: max-age=300says the response is fresh for 300 seconds.privateallows a private browser cache but not a shared cache;no-storeasks caches not to store it.- An ETag is a validator. The client sends
If-None-Match; the server can answer304 Not Modifiedwith no representation body. Last-ModifiedandIf-Modified-Sinceoffer a time-based validator.
“No cache” is ambiguous in conversation. In HTTP, no-cache permits storage but requires revalidation before reuse; no-store prohibits storage.
HTTP/1.1, HTTP/2 and HTTP/3
| Version | Transport | How requests share a connection | Main advance |
|---|---|---|---|
| HTTP/1.1 | Usually TCP | Sequential or limited pipelining; browsers open several connections | Persistent connections, universal Host header |
| HTTP/2 | Usually TLS over TCP | Many binary streams multiplexed in one connection | Header compression and concurrent streams |
| HTTP/3 | QUIC over UDP | Many independent QUIC streams | Loss in one stream need not stall all others; faster connection setup |
HTTP/2 does not make TCP packet loss disappear: all streams share one ordered TCP byte stream. QUIC implements stream-level ordering, encryption and transport together, which is why HTTP/3 can isolate that delay. The HTTP meaning—methods, status codes, fields and resources—largely stays the same.
The layers in one sentenceDNS finds the server, IP routes towards it, TCP or QUIC moves data, TLS protects it, and HTTP says what the client and server mean.