Choosing the right status code helps clients understand what happened and how to respond. This guide covers common scenarios for both traditional web applications and REST APIs.
General Web Scenarios
These status codes apply across all types of web applications:
REST API: CRUD Operations
REST APIs map HTTP methods to Create, Read, Update, and Delete operations. The status code should reflect both the operation type and its outcome.
GET (Read)
POST (Create)
PUT (Replace) & PATCH (Partial Update)
DELETE
Error Handling Patterns
Consistent error responses help API consumers handle failures gracefully:
Idempotency
Idempotent operations produce the same result regardless of how many times they're called. This is important for retry logic and reliability. GET, PUT, and DELETE should be idempotent; POST typically is not.
The idempotent approach (returning success for already-deleted resources) simplifies client retry logic, since clients don't need to distinguish between "deleted now" and "already deleted."