Methods: the verb of the request
The method at the start of the request line says what kind of action you want:
| Method | Meaning | Has a body? |
|---|---|---|
GET | read a resource | no |
POST | create something / submit data | yes |
PUT | replace a resource | yes |
PATCH | partially update a resource | yes |
DELETE | remove a resource | usually no |
Browsers mostly send GET (every page, image, and script) and POST (form submissions, logins). The others show up constantly in APIs. A useful rule: GET must be safe, meaning it only reads and changes nothing, which is why a GET can be cached, retried, and prefetched freely (unit 8 builds on this).
REST: the convention that makes methods useful
Methods only pay off if everyone agrees what they act on. REST (Representational State Transfer) is the dominant convention for that: every thing the server manages — a note, a user, an order — is a resource with its own path, and the HTTP method is the verb applied to it:
| Request | Meaning |
|---|---|
GET /notes | list the notes |
GET /notes/17 | read note 17 |
POST /notes | create a new note |
PATCH /notes/17 | update part of note 17 |
DELETE /notes/17 | remove note 17 |
An API built this way is called a REST API. The convention exists because the alternative was chaos: before it, every service invented its own verbs (/getNote?op=del&id=17), and every integration meant reading someone's manual. With REST, an engineer who knows the resource path can usually guess the entire API. You will drive one with curl in unit 5.
Quiz
Following REST conventions, what does the request PATCH /users/42 do?
Status codes: the result, in one number
The first digit of the status code puts it in a class:
| Class | Meaning | Famous members |
|---|---|---|
2xx | success | 200 OK, 201 Created |
3xx | redirect, look elsewhere | 301 Moved Permanently, 304 Not Modified |
4xx | client's fault | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found |
5xx | server's fault | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable |
The 4xx/5xx split is the single most useful debugging fact in HTTP: a 4xx means your request was wrong (bad URL, missing login, no permission), a 5xx means the server broke while handling a request it understood. You will lean on this hard in the unit 9 capstone.
Code exercise · bash
Your turn. Classify each status code by its first digit using a case statement. Patterns like 2*) match any code starting with 2. Print each code and its class as shown in the expected output.
Quiz
An API returns 403 Forbidden when your script calls it. Whose side is the problem on?
Problem
You want your script to remove the resource at /api/notes/17 on a REST API. Which HTTP method belongs in the request line? (One word.)