Skip to content

HTTP Status Codes for REST APIs

  • HTTP status codes are three-digit numbers returned by web servers to indicate the outcome of a client’s request.
  • In REST APIs, proper use of status codes helps clients understand what happened and how to respond appropriately.

HTTP status codes are organized into five categories based on their first digit:

Indicate that the request was received and is being processed.

  • 100 Continue - Request headers received, client should send request body
  • 101 Switching Protocols - Server is switching protocols as requested

The request was successfully received, understood, and accepted.

  • 200 OK - Request successful, response body contains requested data
  • 201 Created - Resource successfully created
  • 202 Accepted - Request accepted for processing, but not completed
  • 204 No Content - Request successful, no response body needed

Further action needed to complete the request.

  • 301 Moved Permanently - Resource permanently moved to new URL
  • 302 Found - Resource temporarily at different URL
  • 304 Not Modified - Resource unchanged since last request (caching)

The client made an error in their request.

  • 400 Bad Request - Malformed request syntax or invalid data
  • 401 Unauthorized - Authentication required
  • 403 Forbidden - Request understood but access denied
  • 404 Not Found - Requested resource doesn’t exist
  • 405 Method Not Allowed - HTTP method not supported for this resource

The server failed to fulfill a valid request.

  • 500 Internal Server Error - Generic server error
  • 502 Bad Gateway - Invalid response from upstream server
  • 503 Service Unavailable - Server temporarily unavailable

Status CodeWhen to UseResponse Body
200 OKSuccessfully retrieved resource(s)Resource data
304 Not ModifiedResource unchanged (conditional GET)Empty
400 Bad RequestInvalid query parameters or request formatError details
401 UnauthorizedAuthentication requiredError message
403 ForbiddenAccess denied to authenticated userError message
404 Not FoundResource doesn’t existError message
406 Not AcceptableRequested format not availableError message
500 Internal Server ErrorServer error during retrievalError message

Examples:

GET /api/planets/123
200 OK - Returns planet data
404 Not Found - Planet doesn't exist
http

Status CodeWhen to UseResponse Body
201 CreatedResource successfully createdCreated resource + Location header
202 AcceptedCreation request accepted, processing asyncStatus information
400 Bad RequestInvalid or missing required dataValidation errors
401 UnauthorizedAuthentication requiredError message
403 ForbiddenNot authorized to create resourcesError message
409 ConflictResource already exists or conflicts with current stateError details
422 Unprocessable EntityValid syntax but semantic errorsValidation errors
500 Internal Server ErrorServer error during creationError message

Examples:

POST /api/planets
201 Created - Planet created successfully
400 Bad Request - Missing required field "name"
409 Conflict - Planet with this name already exists
http

Status CodeWhen to UseResponse Body
200 OKResource successfully updatedUpdated resource
201 CreatedResource created (if it didn’t exist)Created resource
204 No ContentResource updated, no response body neededEmpty
400 Bad RequestInvalid data or request formatError details
401 UnauthorizedAuthentication requiredError message
403 ForbiddenNot authorized to update resourceError message
404 Not FoundResource to update doesn’t existError message
409 ConflictUpdate conflicts with current resource stateError details
422 Unprocessable EntityValid syntax but semantic errorsValidation errors
500 Internal Server ErrorServer error during updateError message

Examples:

PUT /api/planets/123
200 OK - Planet updated successfully
404 Not Found - Planet doesn't exist
422 Unprocessable Entity - Invalid diameter value
http

Status CodeWhen to UseResponse Body
200 OKPartial update successfulUpdated resource
204 No ContentPartial update successful, no response bodyEmpty
400 Bad RequestInvalid patch format or dataError details
401 UnauthorizedAuthentication requiredError message
403 ForbiddenNot authorized to update resourceError message
404 Not FoundResource to patch doesn’t existError message
409 ConflictPatch conflicts with current stateError details
422 Unprocessable EntityInvalid field valuesValidation errors
500 Internal Server ErrorServer error during patchError message

Examples:

PATCH /api/planets/123
200 OK - Planet diameter updated
404 Not Found - Planet doesn't exist
http

Status CodeWhen to UseResponse Body
200 OKResource deleted, returning final stateFinal resource state
204 No ContentResource successfully deletedEmpty
202 AcceptedDelete request accepted, processing asyncStatus information
401 UnauthorizedAuthentication requiredError message
403 ForbiddenNot authorized to delete resourceError message
404 Not FoundResource to delete doesn’t existError message
409 ConflictResource can’t be deleted due to dependenciesError details
500 Internal Server ErrorServer error during deletionError message

Examples:

DELETE /api/planets/123
204 No Content - Planet deleted successfully
404 Not Found - Planet doesn't exist
409 Conflict - Planet has associated moons, can't delete
http

Used for rate limiting when client exceeds allowed request frequency.

429 Too Many Requests
Retry-After: 60
http

When the request payload format is not supported.

POST /api/planets
Content-Type: application/xml
415 Unsupported Media Type - Only JSON supported
http

When conditional headers (If-Match, If-Unmodified-Since) fail.

PUT /api/planets/123
If-Match: "etag123"
412 Precondition Failed - Resource was modified
http