REST API Status Codes and Error Response Design

Practical HTTP status codes, error response bodies, validation failures, and troubleshooting-friendly API error contracts.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Success status codes

Return the narrowest success code that matches the outcome.

200 OK

Standard success response with a body.

httpANYhttp200success
http
HTTP/1.1 200 OK
Notes

Use `200 OK` for successful reads and updates when you are returning a representation.

201 Created

Successful resource creation.

httpANYhttp201created
http
HTTP/1.1 201 Created
Location: /users/usr_123
Notes

`201 Created` is ideal when a new resource has been created and you can identify its URL.

202 Accepted

Accepted for asynchronous processing.

httpANYhttp202async
http
HTTP/1.1 202 Accepted
Notes

Use this when the work has started or been queued but is not finished yet.

204 No Content

Success without a response body.

httpANYhttp204empty-body
http
HTTP/1.1 204 No Content
Notes

Common for deletes and some updates where the client does not need a representation back.

304 Not Modified

Cache validation succeeded; body omitted.

httpANYhttp304cache
http
HTTP/1.1 304 Not Modified
Notes

Useful with ETag or Last-Modified validators for efficient client caching.

Client and server errors

Distinguish invalid input, missing auth, conflicts, and server failures.

400 Bad Request

Malformed request syntax or invalid shape.

httpANYhttp400client-error
http
HTTP/1.1 400 Bad Request
Notes

Use 400 when the request cannot be understood or parsed as sent.

401 Unauthorized

Missing or invalid authentication credentials.

httpANYhttp401auth
http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer
Notes

401 means the client needs valid authentication. It is not the same as lacking permission.

403 Forbidden

Authenticated but not allowed to perform the action.

httpANYhttp403authorization
http
HTTP/1.1 403 Forbidden
Notes

Return 403 when the identity is known but access is denied.

404 Not Found

The resource does not exist.

httpANYhttp404missing
http
HTTP/1.1 404 Not Found
Notes

Use 404 when the targeted resource cannot be found or should not be disclosed.

409 Conflict

Request conflicts with current resource state.

httpANYhttp409conflict
http
HTTP/1.1 409 Conflict
Notes

Common for uniqueness violations, version conflicts, and invalid state transitions.

412 Precondition Failed

Optimistic concurrency guard failed.

httpANYhttp412etag
http
HTTP/1.1 412 Precondition Failed
Notes

A strong fit when using conditional requests such as `If-Match` with ETags.

422 Unprocessable Content

Well-formed request but semantic validation failed.

httpANYhttp422validation
http
HTTP/1.1 422 Unprocessable Content
Notes

Use 422 when the JSON shape is valid but business validation rules are not satisfied.

429 Too Many Requests

The client exceeded the rate limit.

httpANYhttp429rate-limit
http
HTTP/1.1 429 Too Many Requests
Retry-After: 60
Notes

Useful for API abuse protection and fair usage enforcement.

500 Internal Server Error

Unexpected server-side failure.

httpANYhttp500server-error
http
HTTP/1.1 500 Internal Server Error
Notes

Reserve 500 for unhandled errors or unknown failures; do not use it for predictable validation problems.

Error response body

Return structured error details clients can act on.

Standard error object

A compact structured error response.

jsonANYresterrorsjson
json
{
  "error": {
    "code": "EMAIL_ALREADY_EXISTS",
    "message": "An account with that email already exists.",
    "details": {
      "field": "email"
    },
    "request_id": "req_01HXYZ..."
  }
}
Notes

Machine-readable codes plus a human-readable message help both client UX and support troubleshooting.

Validation errors by field

Return multiple field-level issues at once.

jsonANYrestvalidationfields
json
{
  "error": {
    "code": "VALIDATION_FAILED",
    "message": "One or more fields are invalid.",
    "fields": [
      { "name": "email", "code": "INVALID_FORMAT" },
      { "name": "password", "code": "TOO_SHORT" }
    ]
  }
}
Notes

Returning all field failures reduces trial-and-error for API consumers and form builders.

Recommended next

No recommendations yet.