Логотип Workflow

Article

Http Response Statuses

Stage 4. Response Status Codes

HTTP status code is the first result signal your server provides. Client SDKs, retry engines, dashboards, and alerts primarily react to that signal. For that reason, status code discipline is part of production reliability, not cosmetic API style.

Status codes map

A practical way to reason about codes is through three groups. 2xx means successful processing. 4xx means request/client/context issue. 5xx means server-side failure. Teams that apply this mapping consistently gain faster incident triage and clearer operational metrics.

In day-to-day API work, a small subset of codes matters most. 200 OK for successful read/update with body, 201 Created for creation, 204 No Content for successful operations without payload. On the failure side, 400, 401, 403, 404, 409, and 422 cover most client-facing problems, while 500 represents unexpected server faults.

The "always return 200" pattern feels convenient early, but it breaks protocol semantics. Clients must parse custom body flags, monitoring loses true error signals, and retries misbehave. Over time this creates brittle client logic and expensive maintenance.

Status and body should reinforce each other. A 409 Conflict should include a conflict-oriented message and machine-readable type, not a generic failure string. Integration teams often automate behavior based on the combination of status and error type.

{
  "error": "conflict",
  "message": "order already confirmed",
  "traceId": "a733ed51"
}

401 vs 403 is another high-value distinction. 401 means authentication is missing or invalid. 403 means authentication is valid but permissions are insufficient. Mixing these codes causes poor UX and incorrect client recovery behavior.

422 Unprocessable Entity is useful when JSON is syntactically valid but violates business constraints. This cleanly separates malformed input (400) from semantically invalid action (422), especially helpful for complex form workflows.

Consistency across endpoints is critical. If identical failure scenarios produce different status codes in different modules, clients become branch-heavy and QA matrices explode. A stable status policy reduces both integration cost and support load.

HTTP Status Reference Table

ClassCodeNamePractical meaning
1xx100ContinueRequest headers were received; client can continue sending the body.
1xx101Switching ProtocolsServer agrees to switch protocol as requested.
1xx103Early HintsPreliminary response so the client can preload linked resources.
2xx200OKStandard success response.
2xx201CreatedRequest succeeded and created a new resource.
2xx202AcceptedRequest accepted for processing, but not finished yet.
2xx203Non-Authoritative InformationSuccess, but returned metadata/body may come from a transformed or secondary source.
2xx204No ContentSuccess with no response body.
2xx205Reset ContentSuccess with no body; client should reset its current view/form state.
2xx206Partial ContentServer returned only part of the resource (range request).
3xx300Multiple ChoicesMultiple representations/targets are available.
3xx301Moved PermanentlyResource permanently moved to a new URL.
3xx302FoundResource temporarily located at another URL.
3xx303See OtherClient should retrieve result at another URL (commonly after POST).
3xx304Not ModifiedCached version is still valid; no new payload needed.
3xx307Temporary RedirectTemporary redirect while keeping the original HTTP method.
3xx308Permanent RedirectPermanent redirect while keeping the original HTTP method.
4xx400Bad RequestServer cannot process the request because syntax/shape is invalid.
4xx401UnauthorizedAuthentication is missing, invalid, or failed.
4xx402Payment RequiredReserved code; generally not used in normal APIs.
4xx403ForbiddenAuthenticated (or understood), but operation is not allowed.
4xx404Not FoundRequested resource cannot be found.
4xx405Method Not AllowedHTTP method is not supported for this resource.
4xx406Not AcceptableServer cannot produce a response matching client Accept constraints.
4xx407Proxy Authentication RequiredClient must authenticate with the proxy first.
4xx408Request TimeoutServer timed out waiting for the request.
4xx409ConflictRequest conflicts with current resource state.
4xx410GoneResource was removed and is no longer available.
4xx411Length RequiredContent-Length header is required but missing.
4xx412Precondition FailedConditional request precondition evaluated to false.
4xx413Request Too LargeRequest body is larger than server limit.
4xx414Request-URI Too LongURI is longer than the server is willing to process.
4xx415Unsupported Media TypePayload media type is not supported.
4xx416Range Not SatisfiableRequested byte range cannot be served.
4xx417Expectation FailedServer cannot satisfy the Expect header requirements.
5xx500Internal Server ErrorGeneric unexpected server-side failure.
5xx501Not ImplementedServer does not support requested method/behavior.
5xx502Bad GatewayUpstream service returned an invalid response.
5xx503Service UnavailableServer is unavailable (overloaded or down).
5xx504Gateway TimeoutUpstream service did not respond in time.
5xx505HTTP Version Not SupportedServer does not support the request's HTTP version.
5xx511Network Authentication RequiredNetwork access requires authentication first.

Practical scenario

In a payment API, duplicate-operation conflict returned 409 in one endpoint but 200 with success=false in another. Mobile clients treated one flow as success and suppressed user warnings. After status normalization and unified error schema, client behavior became consistent, support tickets dropped, and monitoring finally reflected real conflict rates.

Quiz

Check what you learned

Please login to pass quizzes.