HTTP Methods: GET, POST, PUT, DELETE Semantics
What You'll Learn
You'll learn how HTTP verbs define operations on RESTful resources and understand their critical safety and idempotency guarantees.
Core HTTP Method Semantics
Building on REST's resource-oriented architecture, HTTP methods define what action you're performing on a resource. Each method carries specific contracts:
GET: Safe and Idempotent
GET retrieves a resource without side effects. It's safe (doesn't modify server state) and idempotent (calling it 100 times has the same effect as calling once). Think of it like looking at a book on a shelf—you can look all day without changing anything.
GET /users/123
POST: Neither Safe nor Idempotent
POST creates new resources or triggers actions. It's not safe (changes state) and not idempotent (multiple calls create multiple resources). Like mailing letters—each time you mail one, a new letter arrives.
POST /users
PUT: Idempotent but Not Safe
PUT replaces an entire resource. It's idempotent (setting the same value repeatedly produces the same result) but not safe (modifies state). Like painting a wall—whether you apply the same coat once or twice, the wall looks identical.
PUT /users/123
DELETE: Idempotent but Not Safe
DELETE removes a resource. It's idempotent (deleting an already-deleted resource still results in "not found") but not safe. Like erasing a whiteboard—erasing the same spot twice has the same outcome.
DELETE /users/123
Why These Guarantees Matter
Idempotency is crucial for retry logic—if a network timeout occurs, you can safely retry PUT or DELETE without worrying about duplicate effects. Safety enables aggressive caching for GET requests.
Key Takeaway: HTTP methods carry semantic contracts—GET is safe and idempotent (retrieval), POST is neither (creation), PUT and DELETE are idempotent but not safe (modification/deletion). Design APIs respecting these guarantees to enable reliable distributed systems.