← Back to Library Web Development Beginner 8 min read

How HTTP Works: Requests, Responses, and Status Codes

HTTP (Hypertext Transfer Protocol) is the foundational application-layer protocol that powers the World Wide Web, establishing the request-and-response rules for browsers to retrieve web pages, images, and API data from remote web servers.

💡 Plain-English Analogy

When you type a web address into your browser, your computer sends an HTTP letter asking "Please send me the home page." The server receives the letter, checks if the file exists, and writes an HTTP response letter back saying "Here is your page (Status 200 OK)" along with the website code.

⚙️ Architecture & Under the Hood

HTTP operates at Layer 7 of the OSI model, historically over TCP on port 80/443. HTTP is stateless by design, requiring session cookies or bearer tokens to maintain user state. HTTP/2 introduced binary framing, multiplexing, and header compression (HPACK), while HTTP/3 transitions to UDP via the QUIC transport protocol to eliminate head-of-line blocking.

Core HTTP Request Methods (Verbs)

HTTP defines an explicit set of request methods that indicate the desired action to be performed on the identified resource.

  • GET: Requests representation of the specified resource. Must be safe and idempotent (read-only).
  • POST: Submits an entity to the specified resource, often causing a change in state or side effects on the server.
  • PUT: Replaces all current representations of the target resource with the request payload.
  • PATCH: Applies partial modifications to a resource.
  • DELETE: Deletes the specified resource.

Understanding HTTP Status Codes by Category

Every HTTP response carries a 3-digit status code that signals the outcome of the request.

1xx Informational  ─ Request received, continuing process
2xx Success        ─ 200 OK, 201 Created, 204 No Content
3xx Redirection    ─ 301 Moved Permanently, 304 Not Modified
4xx Client Error   ─ 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found
5xx Server Error   ─ 500 Internal Server Error, 502 Bad Gateway, 503 Unavailable

Frequently Asked Questions

What is the difference between HTTP and HTTPS?

HTTPS is HTTP wrapped in a secure TLS/SSL encrypted tunnel. Data sent over standard HTTP is transmitted in plain text and can be intercepted on public Wi-Fi, while HTTPS encrypts all communication.

What is HTTP keep-alive?

Keep-alive allows a single TCP connection to remain open across multiple HTTP requests and responses, significantly reducing the latency overhead of establishing new TCP handshakes for each asset.