HTTP Messages
An HTTP exchange is a request from the client and a response from the server. Each message has a start line, headers, and an optional body.
Request shape
GET /about HTTP/1.1 Host: example.com User-Agent: Mozilla/5.0 Accept: text/html Accept-Language: en-US (empty body for GET)
Response shape
HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 1543 Cache-Control: max-age=3600 <!DOCTYPE html>…
Important status codes
| Class | Code | Meaning |
|---|---|---|
| 2xx Success | 200 | OK |
| 201 | Created | |
| 204 | No Content | |
| 3xx Redirection | 301 | Moved Permanently |
| 302 | Found (temporary redirect) | |
| 304 | Not Modified (cache hit) | |
| 4xx Client errors | 400 | Bad Request |
| 401 | Unauthorized | |
| 403 | Forbidden | |
| 404 | Not Found | |
| 409 | Conflict | |
| 422 | Unprocessable Entity | |
| 429 | Too Many Requests | |
| 5xx Server errors | 500 | Internal Server Error |
| 502 | Bad Gateway | |
| 503 | Service Unavailable | |
| 504 | Gateway Timeout |
Tip: Open your browser's dev tools and switch to the Network tab. Every request and response is right there, headers and all — the best way to learn HTTP is to watch real traffic.
Example
Example
<!DOCTYPE html>
<html>
<head>
<title>HTTP Messages</title>
</head>
<body>
<h1>HTTP Messages</h1>
<p>This is a demo page for the "HTTP Messages" lesson.</p>
</body>
</html>
Try it Yourself »
Exercise
What HTTP status code means "OK, success"?
HTTP
OK
A three-digit number starting with 2.
Discussion
Loading…