I am working on designing restful apis. Sometimes it is not easy to decide on what http status code to return for a condition. I went through restful standards on various sites and some of the commonly used restful apis and concluded with following commonly used status codes.
| Status code | Description |
|---|---|
| 500 | Any unexpected server-side error. Client is expected to retry. |
| 200 | Success is performing the action. Creation of a resource should use 201 instead |
| 201 | Success in creating a resource |
| 301 | Service requires https whereas the request was using http |
| 401 | Authentication failure – bad user name, bad password |
| 404 | Resource represented by the url of the request is not found |
| 400 | Bad request. Client should make some changes in the request and resend |
| 403 | Forbidden. Additional information should be sent to specify what is the recourse. The resource should exist, the client should have required auth. |
| 402 | Bad session id. |
| 409 | Client is creating a duplicate record. If an already existing resource id is passed in the request. It may also be sent if some of the fields violate any unique constraint on the resources |
| 412 | Some precondition for performing an action is missing. It could be absence of a header or some other criteria |
| 413 | Request entity too large |