Rest API – HTTP Status Codes

While designing the Rest API, it is essential to return correct HTTP status codes to the client, which helps them to act accordingly. It also helps API consumers to act differently whenever they are getting an unexpected status code. For example, whenever the client receives some error status code for a specific action method, they can perform a different operation. Your Rest API doesn't need to support all HTTP status codes. In this article, we discuss some of the HTTP status codes for Rest API CRUD operations.

Create: Supported by Rest API POST HTTP verb. There are three important status codes for the POST method.

201 – Created – Whenever resource created successfully
400 – Bad Request – Whenever Rest API receives a bad request. Here client's responsibility to send the request in the correct format.
500 – Internal Server Error – If any technical error occurs within the Rest API. It is the Rest API developer's responsibility to resolve the error.

Read: Supported by Rest API GET HTTP verb. With this operation, we have three important HTTP status codes.

200 – OK – requested resource returned successfully
404 – Not Found – requested resource not found
400 – Bad input request as discussed in Create operation
500 – Internal Server Error as discussed in Create operation

Update: Supported by the Rest API PUT method. It has four crucial HTTP status codes.

200 – OK – requested resource updated successfully
404 – Not Found – requested resource not found to update
400 – Bad input request as discussed in Create operation
500 – Internal Server Error as discussed in Create operation

Delete: Supported by Rest API DELETE HTTP verb. It also has four crucial HTTP status codes.

204 – Success, no content returned – Requested resource deleted successfully, and no content returned.
404 – Not Found – requested resource not found to delete
400 – Bad input request as discussed in Create operation
500 – Internal Server Error as discussed in Create operation

Other than these four methods, Rest API supports one more method PATCH, which used to update the part of the resource.

PATCH verb also returns four HTTP status codes same as PUT as given below.

200 – OK – requested resource updated successfully
404 – Not Found – requested resource not found to update
400 – Bad input request as discussed in Create operation
500 – Internal Server Error as discussed in Create operation

There are some more general status codes available; those are 401, 403.

401 – UnAuthorized – Invalid credentials or No credentials provided.
403 – Forbidden – Authentication succeeded, but authorization failed. That means the user does not have access to a specific resource.

Add comment