HTTP status codes
Коды ответа HTTP
A three-digit number in an HTTP response tells the client what happened to its request. For example, 200 means the request succeeded, while 404 means the requested resource was not found.
Also known as: 404, 500, статус-коды
What a status code tells you
When a browser or an API client sends an HTTP request, the status code gives it the outcome without requiring it to read the response body. A browser might follow a redirect; an API client might ask the user to sign in again. The code describes the outcome, while headers and the body can supply details. The response can come from the application or from an intermediary such as a reverse proxy.
How to read the first digit
- 1xx: Informational. These responses come before the final response. For example,
100 Continuetells a client it can go ahead and send the request body. - 2xx: Success.
200 OKis the general success code.201 Createdmeans a resource was created,202 Acceptedmeans work was accepted but has not finished, and204 No Contentmeans success with no response body. - 3xx: Redirection. Many of these codes direct the client to another URL.
304 Not Modifiedis different: it tells a client that checked a cached copy that it can keep using it. - 4xx: Client error. Examples include malformed input (
400 Bad Request), a missing resource (404 Not Found), a conflict with current state (409 Conflict), and exceeding a request limit (429 Too Many Requests). The class describes the response, not necessarily who is to blame. - 5xx: Server error.
500 Internal Server Erroris a general unexpected failure.503 Service Unavailablecan indicate temporary overload or maintenance.504 Gateway Timeoutmeans a gateway did not receive a timely response from an upstream server.
Example: deleting a saved item
Suppose an API receives DELETE /bookmarks/42, removes the bookmark, and has nothing else to return. Its HTTP/1.1 response can be:
HTTP/1.1 204 No Content
The client can remove the bookmark from the screen without trying to parse JSON. If the API needs to send a result document, use 200 OK with that document instead: a 204 response cannot have a body.
Common mistakes and interview scenarios
Avoid sending 200 OK for an HTTP-level failure and putting the only error signal in JSON. Client libraries and dashboards may then count failures as successes. In tests, check both the status and, when relevant, the error details or headers.
Interviewers often ask what happens when the same DELETE is sent twice. An API might return 204 on the first call and 404 on the second. That does not make DELETE non-idempotent: the intended effect is the same whether the client sends the request once or repeatedly—the bookmark is gone. Idempotency does not require identical responses.