The HTTP specification dictates that any response must have a three-digit status code that allows programs to determine the nature of the response. These codes allow a program to process the response efficiently:
| Status code | Class of response | Description |
| 1xx | Informational | The request was received but not yet fully processed. The client doesn't need to do anything. |
| 2xx | Success | The request was successfully received, understood, and accepted. |
| 3xx | Redirection | The resource has moved, either temporarily or permanently. The client needs to take further actions to complete the request. |
| 4xx | Client error | The request is syntactically and/or semantically incorrect, and the server was unable (or refused) to process it. |
| 5xx | Server error | The request is likely to be valid, but there was an error on the server. |
We have already followed these standards for our Create User endpoint. For instance, we respond with a 415 Unsupported Media Type error status code when the request payload is not JSON; Express will automatically respond with a 404 Not Found error if the client tries to hit an endpoint that is not implemented.
According to IANA, there are currently 62 assigned HTTP status codes. Most developers won't be able to memorize all 62. Thus, many APIs restrict the number of status codes they send back. We will do the same, and limit our API to using only the following nine status codes:
- 200 OK: Generic successful operation.
- 201 Created: Successful operation where a resource, such as a user, is created.
- 400 Bad Request: When the request is syntactically or semantically incorrect.
- 401 Unauthorized: When the request lacks authentication credentials so the server cannot determine who is sending the request. The client should resend the request with these credentials.
- 403 Forbidden: The server understands the request but does not authorize it.
- 404 Not Found: The resource is not found, or the endpoint path is invalid.
- 409 Conflict: The resource has been modified after the client last retrieved it. The client should request a new version of the resource and decide whether it'd like to send the request again.
- 415 Unsupported Media Type: The payload given for this endpoint is in an unsupported format, for example, sending an XML payload when the server only accepts JSON.
- 500 Internal Server: The request is most likely to be valid, but there's an error on the server.