HTTP Methods
HTTP methods tell an API what action you want to perform. Think of them as verbs — the building blocks of every API interaction.
The CRUD Connection
Most APIs are built around CRUD operations — Create, Read, Update, Delete. Each maps to HTTP methods:
| CRUD | HTTP Method | Example |
|---|---|---|
| Create | POST | POST /api/training/users |
| Read | GET | GET /api/training/users/1 |
| Update | PUT or PATCH | PATCH /api/training/users/1 |
| Delete | DELETE | DELETE /api/training/users/1 |
GET Read dataRetrieves data without changing anything. Safe and idempotent — calling it multiple times has the same result.
Examples
- GET /api/training/users — list all users
- GET /api/training/users/1 — get user with id 1
- GET /api/training/posts?userId=2 — get posts by user 2
Rules
- • No request body needed
- • Can be bookmarked/cached
- • Should never modify data
POST Create dataCreates a new resource. Not idempotent — calling it twice creates two records.
Examples
- POST /api/training/users — create a new user
- POST /api/training/posts — publish a new post
- POST /api/training/todos — add a new todo item
Rules
- • Send data in the request body as JSON
- • Server returns 201 Created on success
- • Returns the newly created resource
PUT Replace dataReplaces an entire resource. You must send all fields, not just the ones you want to change.
Examples
- PUT /api/training/users/1 — replace user 1 with new data
- PUT /api/training/posts/3 — replace post 3 completely
Rules
- • Must include ALL fields in the body
- • Omitted fields may be cleared
- • Idempotent — same result if repeated
PATCH Update fieldsUpdates only the fields you specify, leaving everything else unchanged. More surgical than PUT.
Examples
- PATCH /api/training/todos/1 — toggle just the completed field
- PATCH /api/training/users/2 — update just the city
Rules
- • Only include fields you want to change
- • Other fields are preserved
- • Returns the updated resource
DELETE Remove dataRemoves a resource permanently. Use with care — that's why the Oopsie Reset button exists!
Examples
- DELETE /api/training/users/1 — delete user 1
- DELETE /api/training/posts/5 — delete post 5
Rules
- • Usually no request body needed
- • Returns 200 or 204 on success
- • Resource is gone — no undo (unless you have a reset!)
PUT vs PATCH — The Key Distinction
This trips up a lot of beginners. Here's a concrete example with our training API:
// User 1 currently looks like this:
{ "id": 1, "name": "Alice Johnson", "email": "[email protected]", "city": "Chicago" }PUT /api/training/users/1 — full replacement
{ "name": "Alice Smith", "email": "[email protected]" }
// Result: city is now empty string — PUT requires ALL fieldsPATCH /api/training/users/1 — partial update
{ "name": "Alice Smith" }
// Result: only name changed, city stays "Chicago" ✓