Lesson 1 of 7 · 10 min · 1 hands-on step
HTTP: Requests & Responses
The language browsers and servers speak, taken apart line by line.
A conversation in plain text
When you open a page, your browser sends a request like this:
GET /courses HTTP/1.1
Host: crayoninterview.com
Accept: text/html
Cookie: session=abc123
And the server sends back a response:
HTTP/1.1 200 OK
Content-Type: text/html
Cache-Control: max-age=60
<!doctype html><html>…
That's HTTP: a request line (or status line), headers (extra details), a blank line, then an optional body.
Methods: what you want to do
| Method | Meaning | Example |
|---|---|---|
GET |
read | load a page or a list of courses |
POST |
create | sign up, add a comment |
PUT / PATCH |
replace / update | edit your profile |
DELETE |
remove | delete a post |
Status codes: how it went
| Range | Meaning | Common ones |
|---|---|---|
| 2xx | success | 200 OK, 201 Created, 204 No Content |
| 3xx | go elsewhere | 301 Moved, 304 Not Modified |
| 4xx | you (the client) made a mistake | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests |
| 5xx | the server broke | 500 Internal Server Error, 503 Unavailable |
Try it in the browser
Open DevTools (right-click → Inspect) on any site, go to the Network tab, and reload. Every line is a request. Click one to see its method, status, headers and response. You'll use this tab almost every day as a web developer.
const url = new URL("https://crayoninterview.com/courses?page=2&sort=new");
console.log(url.pathname, Object.fromEntries(url.searchParams));🧪 Practice
Raw HTTP requests are just text. Write parseRequest(raw) that returns { method, path, headers } where headers is an object with lowercase header names.
The first line looks like GET /courses?page=2 HTTP/1.1, then one Name: value header per line.
function parseRequest(raw) {
const lines = raw.split("\n");
return { method: "", path: "", headers: {} };
}
Output appears here. Press Run or Ctrl/⌘ + Enter.
✅ Check your understanding
Which status code means "Not Found"?
Which HTTP method should never change data on the server?
Create a free account to track your progress.