Status codes tell the client whether the request succeeded, failed because of the client (4xx), or failed because of the server (5xx). Using them correctly helps clients retry, show errors, and cache correctly.
| Code | Meaning | When to use |
|---|---|---|
| 200 | OK | Success (GET, PUT, PATCH) |
| 201 | Created | Resource created (POST), include Location header |
| 204 | No Content | Success, no body (e.g. DELETE) |
| 400 | Bad Request | Invalid input, malformed body |
| 401 | Unauthorized | Not authenticated (login / token missing or invalid) |
| 403 | Forbidden | Authenticated but not allowed to do this |
| 404 | Not Found | Resource doesn’t exist (or hide existence with 403) |
| 500 | Internal Server Error | Unexpected server bug |
| 502 | Bad Gateway | Invalid response from upstream |
| 503 | Service Unavailable | Overloaded or down; retry later |
401 vs 403: Use 401 when the user is not identified (missing or bad credentials). Use 403 when the user is known but not permitted to perform the action.