HTTP Methods
GET, POST, PUT, PATCH, DELETE — what they mean and when to use them
Skills taught: web.http-methods, web.idempotency, web.rest-verbs
Methods are semantic verbs
HTTP methods tell the server — and every layer in between (caches, proxies, load balancers) — what kind of operation the request intends. Using the right method is not just convention; it affects caching, retries, and security.
Method Safe? Idempotent? Has body? Use for
────── ───── ─────────── ───────── ──────────────────────────────────
GET Yes Yes No Read / fetch a resource
HEAD Yes Yes No Same as GET but no response body
POST No No Yes Create a resource or trigger action
PUT No Yes Yes Replace a resource completely
PATCH No No Yes Partial update of a resource
DELETE No Yes No Remove a resource
OPTIONS Yes Yes No Check allowed methods (CORS preflight)
Safe = no server-side changes (can be retried freely)
Idempotent = multiple identical calls = same result as one call
Methods in a CRUD API
# CREATE
POST /articles
Content-Type: application/json
{ "title": "Hello", "body": "World" }
→ 201 Created { "id": 7, "title": "Hello" }
# READ (list)
GET /articles
→ 200 OK [{ "id": 1 }, { "id": 7 }]
# READ (single)
GET /articles/7
→ 200 OK { "id": 7, "title": "Hello", "body": "World" }
# UPDATE (replace completely)
PUT /articles/7
{ "title": "Updated title", "body": "Updated body" }
→ 200 OK { "id": 7, "title": "Updated title", "body": "Updated body" }
# UPDATE (partial change — only what you send changes)
PATCH /articles/7
{ "title": "New title only" }
→ 200 OK { "id": 7, "title": "New title only", "body": "World" }
# DELETE
DELETE /articles/7
→ 204 No Content (no body)
Tip: PUT vs PATCH: PUT replaces the entire resource — any fields you omit go blank. PATCH only changes the fields you include. Use PATCH for editing a single field (e.g. updating just a user's email address).
Frequently Asked Questions
Can I send a body with a GET request?
Technically yes, but you should not. Many proxies, servers, and libraries strip the body from GET requests. Use query string parameters instead: GET /search?q=kernal. The HTTP spec says GET requests should have no semantic meaning to the body.
What is idempotency and why does it matter?
An idempotent operation produces the same result no matter how many times you call it. DELETE /articles/1 twice has the same result as calling it once — the article is gone. This matters for reliability: if your network drops after sending a request, you may not know if it succeeded. For idempotent methods, you can safely retry. For POST (not idempotent), you might create duplicates if you retry — which is why payment APIs use Idempotency-Key headers.