HTTP (Hypertext Transfer Protocol) is an application-layer protocol for distributed, collaborative, hypermedia information systems. It's the foundation of data communication for the World Wide Web.
Each request is independent and doesn't retain information about previous requests.
Client sends requests, server responds with data or status information.
Human-readable protocol that's easy to debug and understand.
Separates concerns — browser (client) asks, web server (server) answers.
Retrieve data from server. Safe and idempotent — never modifies data.
GET /api/users HTTP/1.1
Host: example.com
Send data to server to create a new resource. Not idempotent.
POST /api/users HTTP/1.1
Content-Type: application/json
{"name": "John"}
Update an existing resource completely. Idempotent — same result each time.
PUT /api/users/123 HTTP/1.1
Content-Type: application/json
{"name": "Jane"}
Remove a resource. Idempotent — deleting twice has the same effect.
DELETE /api/users/123 HTTP/1.1
Partially update a resource. Only sends changed fields, unlike PUT.
PATCH /api/users/123 HTTP/1.1
{"email": "new@example.com"}
HEAD: Like GET but no body — just headers. OPTIONS: Discover allowed methods.
OPTIONS /api/users HTTP/1.1
→ Allow: GET, POST, PUT
HTTP headers carry metadata about the request or response. Sorted by popularity:
| Header | Type | Description | Example |
|---|---|---|---|
| Content-Type | Response | Media type of the resource | application/json |
| User-Agent | Request | Client application info | Mozilla/5.0... |
| Host | Request | Target server hostname | example.com |
| Accept | Request | Acceptable response types | application/json |
| Cache-Control | Both | Caching directives | no-cache |
| Content-Length | Response | Size of response body | 1024 |
| Authorization | Request | Authentication credentials | Bearer token123 |
| Accept-Encoding | Request | Acceptable compression | gzip, deflate |
| Content-Encoding | Response | Compression used | gzip |
| Connection | Both | Connection control | keep-alive |
| Set-Cookie | Response | Cookie to set on client | session=abc123 |
| Cookie | Request | Cookies to send to server | session=abc123 |
| Location | Response | Redirect URL | https://example.com/new |
| Referer | Request | Previous page URL | https://google.com |
| Accept-Language | Request | Preferred languages | en-US, en |
| X-Forwarded-For | Request | Client IP address (proxy) | 192.168.1.1 |
| ETag | Response | Resource version identifier | "abc123" |
| If-None-Match | Request | Conditional request | "abc123" |
| Server | Response | Server software info | nginx/1.18.0 |
| X-Requested-With | Request | AJAX request indicator | XMLHttpRequest |
Request:
GET /index.html
Response:
<html>...</html>
GET /index.html HTTP/1.0
Host: example.com
HTTP/1.0 200 OK
Content-Type: text/html
GET /page1.html HTTP/1.1
GET /page2.html HTTP/1.1
Connection: keep-alive
# Multiple requests on
# same connection!