Skip to main content

Networking and the web

What is HTTP?

Definition

HTTP is the request-response protocol of the web: a client sends a method, path and headers, and the server replies with a status code, headers and a body.

Also known as: Hypertext Transfer Protocol

HTTP in more detail

Every page load, API call and image fetch is HTTP. The client opens a connection and sends a request line — GET /index.html HTTP/1.1 — followed by headers describing what it wants and can accept, and optionally a body. The server answers with a status line carrying a three-digit code, its own headers, and usually a body. The 1xx codes are informational, 2xx succeeded, 3xx redirect, 4xx blame the request, 5xx blame the server.

HTTP is stateless: the protocol keeps nothing between requests, and the server has no memory of what you asked a moment ago. Everything that feels like continuity — being logged in, a shopping basket — is rebuilt on each request from something the client sends, normally a cookie carrying a session id or a token in an Authorization header.

The protocol has been rewritten twice underneath without changing what it means. HTTP/1.1 sends readable text over one TCP connection at a time. HTTP/2 keeps the same semantics but frames them in binary and multiplexes many streams over one TCP connection. HTTP/3 moves onto QUIC, which runs over UDP, so a lost packet no longer stalls every other stream sharing the connection. The methods, headers and status codes are identical across all three.

HTTP example

GET /articles/12 HTTP/1.1
Host: example.com
Accept: application/json
User-Agent: curl/8.6.0
Cookie: session=8f2c...

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Cache-Control: public, max-age=300
Content-Length: 44

{"id":12,"title":"Introducing the glossary"}

# Status families
# 200 OK   301 Moved Permanently   304 Not Modified
# 400 Bad Request  401 Unauthorized  403 Forbidden
# 404 Not Found    429 Too Many Requests
# 500 Internal Server Error   503 Service Unavailable

HTTP — common questions

What is the difference between HTTP and TCP/IP?
They sit at different layers. IP routes packets between machines and TCP turns that into a reliable ordered stream; HTTP is an application protocol that runs on top of that stream and defines what the bytes mean. HTTP/3 swaps TCP for QUIC over UDP and keeps the same meaning.
What does it mean that HTTP is stateless?
The protocol itself carries no memory from one request to the next. Any continuity must be re-established each time by data the client sends, such as a session cookie or a bearer token, which is what lets any server in a pool handle any request.
What is the difference between 401 and 403?
401 Unauthorized means the request lacked valid credentials — authenticate and try again. 403 Forbidden means the server knows who you are and is refusing anyway. The 401 name is a historical misnomer: it is about authentication, not authorization.

Keep reading

This page explains what HTTP means. For the syntax itself, the HTTP status codes cheat sheet is a full reference of real commands and examples. Every other definition is in the A-Z glossary.

Browse the A-Z glossary