The Plain Picture#
At a library counter you can: look at a book (changes nothing), donate a new book, replace a whole book with a new edition, correct one page, or remove a book. Some actions are harmless to repeat — looking twice changes nothing, removing the same book twice leaves it just as removed. Others aren't — donating twice means two copies.
The Real Names#
| Method | Meaning | StudyBuddy example | Safe? | Idempotent? |
|---|---|---|---|---|
| GET | read a resource | GET /notes/42 | ✅ | ✅ |
| POST | create something / trigger an action | POST /notes (new note) | ❌ | ❌ |
| PUT | replace a resource completely | PUT /notes/42 (whole note) | ❌ | ✅ |
| PATCH | change part of a resource | PATCH /notes/42 (just the title) | ❌ | ❌ (usually) |
| DELETE | remove a resource | DELETE /notes/42 | ❌ | ✅ |
| HEAD | like GET, but headers only | check if a file changed | ✅ | ✅ |
| OPTIONS | "what am I allowed to do here?" | used by browsers for CORS (Security Fundamentals) | ✅ | ✅ |
Safe = doesn't change anything on the server. Only reads.
Idempotent = doing it once or ten times leaves the server in the same state.
DELETE /notes/42five times → the note is gone (the later calls may return 404, but the state is the same).POST /notesfive times → five notes.
Under the Hood — why idempotency matters so much#
Networks fail in the worst possible place (Networking 2: TCP, UDP and Ports Ch 6: an ACK doesn't mean the program finished). Picture this:
App ── POST /payments {amount: 499} ──▶ Server charges the card ✔
App ◀──────── response lost (Wi-Fi drops) ──────── ✗
App: "no reply... retry?"If the request were idempotent, retrying is safe.
It's a POST — retrying may charge Priya twice.
The standard fix is an idempotency key: the client generates a unique ID once and sends it with every retry
(Idempotency-Key: 7f3c…). The server remembers which keys it already processed and returns the saved result instead
of charging again. Stripe's API works exactly this way. You'll build this in How Web APIs Work (coming soon).
Rule of thumb: clients, proxies and load balancers may automatically retry idempotent requests; they must not blindly retry POSTs.
Gotchas
Never change data in a GET. Browsers prefetch links, crawlers follow them, caches replay them. A
GET /notes/42/deletelink will eventually be "clicked" by a bot.PATCH vs PUT: a PUT that leaves out a field should wipe that field (it replaces the whole thing); a PATCH only touches the fields sent. Many real APIs blur this — be explicit in your API docs.
Check yourself
4 questionsWhat's the difference between "safe" and "idempotent"?
Show answerHide answer
Safe = changes nothing. Idempotent = repeating it has the same effect on server state as doing it once (it may change things — the first time).
Is DELETE idempotent? Is POST?
Show answerHide answer
DELETE yes; POST no.
A payment POST times out. Why is a blind retry dangerous, and what's the standard fix?
Show answerHide answer
The first request may have succeeded — the retry could charge twice. Send an idempotency key so the server can detect repeats.
Why should a GET never change data?
Show answerHide answer
Browsers, crawlers and caches issue GETs freely and repeatedly, assuming they're harmless.