BP141: Use correct HTTP status codes

The status code is a standardized way how to communicate a status of processing of the request. Always double-check that the status code you are returning from the server is the right one and that there is no better status code that you could return instead.

Success codes

200 - OK
Use this status code only when there are no more specific 2xx codes.

201 - Created
Use this status code when you have successfuly created a resource on the server.

204 - No Content
Use this status when the request succeeded but there is no representation of the content. It can be used after a resource was deleted or updated.

Client error codes

400 - Bad Request
Use this status code when the request didn't pass validation or is malformed.

401 - Unauthorized
Use this status code when the current user doesn't have permissions to access the resource.

403 - Forbidden
Use this status code when the access to the resource is forbidden, for example because of lock or exceeded quota.

404 - Not Found
Use this status code when

Comments

Anonymous
Incomplete

Download Better Coder application to your phone and get unlimited access to the collection of enterprise best practices.

Get it on Google Play