REST API Status Codes — Choosing the Right HTTP Status Code for API Responses
Informational2xx success
Overview
Complete guide to choosing correct HTTP status codes for REST API responses including CRUD operations, validation errors, and authentication failures.
Key Details
- Using correct HTTP status codes makes APIs self-documenting and follows REST conventions
- 200 OK for successful GET/PUT/PATCH, 201 Created for POST, 204 No Content for DELETE
- 400 Bad Request for validation errors, 401 Unauthorized for missing auth, 403 Forbidden for insufficient permissions
- 404 Not Found for missing resources, 409 Conflict for state conflicts, 422 Unprocessable Entity for semantic errors
- 500 Internal Server Error for unexpected server failures — never expose internal details
Common Causes
- Using 200 for all responses and encoding the actual status in the response body
- Confusing 401 (not authenticated) with 403 (authenticated but not authorized)
- Returning 500 for client errors that should be 4xx
- Using 404 for deleted resources instead of 410 Gone
Steps
- 1Map CRUD to status codes: POST->201, GET->200, PUT->200, PATCH->200, DELETE->204
- 2Use 400 for malformed requests, 422 for well-formed but semantically invalid requests
- 3Return 401 when credentials are missing or invalid, 403 when authenticated but unauthorized for the resource
- 4Use 409 Conflict for duplicate key violations and state transition errors
- 5Always include a machine-readable error code and human-readable message in error response bodies
Tags
rest-apistatus-codesbest-practicescruderror-responses
More in 2xx Success
http-200-okHTTP 200 OK — What It Means & How to Fix It
Informationalhttp-201-createdHTTP 201 Created — What It Means & How to Fix It
Informationalhttp-202-acceptedHTTP 202 Accepted — What It Means & How to Fix It
Informationalhttp-203-non-authoritative-informationHTTP 203 Non-Authoritative Information — What It Means & How to Fix It
Informationalhttp-204-no-contentHTTP 204 No Content — What It Means & How to Fix It
Informationalhttp-205-reset-contentHTTP 205 Reset Content — What It Means & How to Fix It
InformationalFrequently Asked Questions
Use 201 Created for POST requests that create a new resource. Include a Location header with the URL of the new resource. Use 200 OK for PUT/PATCH updates to existing resources.