HTTP — Asking and Answering
Packets can carry anything, so the browser and the server need an agreed way to say "please send me the menu page" and "here it is". That agreement is HTTP, the HyperText Transfer Protocol. Every page, image, stylesheet and script on the bakery site arrives through an HTTP conversation.
The rule
The browser asks with a method and a path; the server answers with a status.
An HTTP request is plain, readable text. Opening the bakery's menu sends something like this:
GET /menu HTTP/1.1
Host: crumbbakery.com
Accept: text/html- Method (
GET): what you want done.GETfetches,POSTsends new data such as an order form,PUTandPATCHupdate,DELETEremoves. - Path (
/menu): which thing on the server. - Headers (
Host,Accept): extra details, one per line, asName: value.
The response comes back in the same shape:
HTTP/1.1 200 OK
Content-Type: text/html
<!DOCTYPE html>
<html>...the menu page...</html>The number is the status code, and its first digit tells you the story:
| Class | Meaning | Examples |
|---|---|---|
| 2xx | It worked | 200 OK, 201 Created |
| 3xx | Look somewhere else | 301 Moved Permanently, 304 Not Modified |
| 4xx | The request was wrong | 404 Not Found, 401 Unauthorized, 403 Forbidden |
| 5xx | The server failed | 500 Internal Server Error, 503 Service Unavailable |
HTTP is stateless: each request stands alone, and the server does not automatically remember the previous one. Sites remember who you are by sending something with every request, most often a cookie.
HTTPS is the same conversation wrapped in encryption (TLS), so nobody on the path can read or quietly change it. Today every public site should use it.