Skip to content

[ADP-200] HTTP Status

reviewing phase 1

  • Re-check documentation necessary.
  • Add related ADPs.

HTTP status codes are standardized codes that indicate the result of an HTTP request. These codes are divided into five categories:

  1. 1xx (Informational): The request was received, and the process is continuing.
  2. 2xx (Success): The request was successfully received, understood, and accepted.
  3. 3xx (Redirection): Further action needs to be taken in order to complete the request.
  4. 4xx (Client Error): The request contains bad syntax or cannot be fulfilled.
  5. 5xx (Server Error): The server failed to fulfill a valid request.

HTTP Status Codes Usage

CodeDescriptionUsageDocumentation
Success Codes
200OKusedocument all
201Createdusedocument POST, PUT
202Acceptedusedocument POST, PUT, PATCH, DELETE
204No Contentusedocument POST, PUT, PATCH, DELETE
205Reset Contentdo not useall
206Partial Contentnot use for paginationall
207Multi-Statususedocument POST (DELETE)
Redirection Codes
301Moved Permanentlydo not useall
302Founddo not useall
303See Otherdo not usePOST, PUT, PATCH, DELETE
304Not ModifieddocumentGET, HEAD
307Temporary Redirectdo not useall
308Permanent Redirectdo not useall
Client Side Error Codes
400Bad Requestusedocument all
401Unauthorizedusedo not document all
403Forbiddendo not documentall
404Not Foundusedo not document all
405Method Not Alloweddocumentall
406Not Acceptableusedo not document all
407Proxy Authentication Requireddo not useall
408Request Timeoutdo not useall
409ConflictdocumentPOST, PUT, PATCH, DELETE
410Gonedo not documentall
411Length RequireddocumentPOST, PUT, PATCH
412Precondition Failedusedo not document PUT, PATCH, DELETE
413Payload Too Largeuseall
415Unsupported Media Typeusedo not document POST, PUT, PATCH
417Expectation Faileddo not useall
418I’m a Teapotdo not useall
422Unprocessable Contentdo not useall
423LockeddocumentPUT, PATCH, DELETE
424Failed Dependencydo not useall
428Precondition Requiredusedo not document all
429Too Many Requestsusedo not document all
431Request Header Fields Too Largedo not documentall
Server Side Error Codes
500Internal Server Errorusedo not document all
501Not Implementeddocumentall
502Bad Gatewayis meaningless
503Service Unavailableusedo not document all
504Gateway Timeoutuseall
505HTTP Version Not Supporteddo not useall
507Insufficient Storagedo not documentPOST, PUT, PATCH
511Network Authentication Requireddo not useall

Legend:

  • use: A common, well-understood status code that should be used where appropriate. This does NOT mean that every operation must return this code.
  • do not use: The status code is not seen as beneficial for returning from a RESTful API. It might be applicable in other contexts, such as being returned by reverse proxies or for web pages.
  • document: If the status code can be returned by the API, it should be documented in the API specification.
  • do not document: The status code has a well-understood standard meaning, so it should only be documented if there are operation-specific details to add.

HTTP Status Codes - Usage Guidelines

CodeDescriptionWhen to UseReason for Do Not Use (if applicable)
Success Codes
200OKStandard success response. Use when the request was successful and there is a response body.
201CreatedUse when a resource has been successfully created. Return the created resource or set the Location header with the URI of the new resource.
202AcceptedUse when the request has been accepted for processing, but the processing is not complete. Applicable for asynchronous operations.
204No ContentUse when the request was successful, but there is no response body (e.g., successful DELETE or PUT request).
205Reset ContentMeant for interactive use cases like clearing a form. No reason to use it in a REST API.
206Partial ContentFor responses to range requests when only a part of the resource indicated by the byte range is returned. Not for pagination, where a normal 200 should be used. Might be useful in rare cases, but most APIs don’t need this.
207Multi-StatusUse for batch or bulk requests where the response contains status for multiple parts. Typically used with POST or DELETE.
Redirection Codes
301Moved PermanentlyThis and all future requests should be directed to the given URI. Not recommended for APIs as redirection codes are generally not used.
302FoundTemporary redirect; some clients may change the method from POST to GET. Mainly used for dismissing and redirecting form submissions in browsers. Not recommended for APIs.
303See OtherIndicates that the response can be found under another URI using a GET method. Not recommended for APIs. The original design is for long running task in API. But we already use 202 + Location to replace it, see ../HTTP%20Semantics%209242628693f84e209daf705d397c27db/%5BADP-357%5D%20Long%20running%20job%20e6872e32e7824847b778f11b7fd373db.md.
304Not ModifiedUse for conditional GET or HEAD requests where the resource has not been modified since the provided date or version.
307Temporary RedirectIndicates that the resource temporarily resides at another URI, keeping the same method. Not recommended for APIs.
308Permanent RedirectIndicates that the resource permanently resides at another URI, keeping the same method. Not recommended for APIs.
Client Side Error Codes
400Bad RequestUse for syntactically incorrect or malformed requests.
401UnauthorizedUse when authentication is required and has failed or has not yet been provided. Often means "Unauthenticated."SHOULD reference common component.responses.UnauthorizedError
403ForbiddenUse when the client does not have permission to access the resource.Only document specific cases.
404Not FoundUse when the requested resource could not be found.SHOULD reference common component.responses.NotFoundError
405Method Not AllowedUse when the HTTP method used is not allowed for the resource.
406Not AcceptableUse when the requested resource can only generate content not acceptable according to the Accept headers sent in the request.
407Proxy Authentication FailedRarely used in API
408Request TimeoutServer times out waiting for the request. Should not be used for APIs.
409ConflictUse when the request could not be processed due to a conflict with the current state of the resource.
410GoneUse when the resource requested is no longer available and will not be available again.
411Length RequiredUse when the server requires a Content-Length header in the request.
412Precondition FailedUse for conditional requests where a precondition is not met. Often used with If-Match for optimistic locking.
413Payload Too LargeRequest headers or body exceed a defined limit. This might happen for large JWT containing many scopes or large HTTP bodies.
415Unsupported Media TypeUse when the media format of the requested data is not supported by the server.
417Expectation FailedClient used an Expect header which the server does not support.
418I’m a TeapotDefined as a joke in RFC 2324.
422Unprocessable EntityServer understands the content type but cannot process the content. 400 covers most use-cases without a clear benefit to differentiating.
423LockedUse when the resource is locked and cannot be accessed. Often used for pessimistic locking.
424Failed DependencyRequest failed due to failure of a previous request. Not applicable to RESTful APIs. Usually used in WebDAV.
428Precondition RequiredUse when the server requires the request to be conditional, to prevent "lost update" problems.
429Too Many RequestsUse when the client has sent too many requests in a given amount of time ("rate limiting").
431Request Header Fields Too LargeServer cannot process the request because the request headers are too large.
Server Side Error Codes
500Internal Server ErrorUse for generic server errors when the server encounters an unexpected condition.
501Not ImplementedUse when the server does not support the functionality required to fulfill the request.
502Bad GatewayServer received an invalid response from an inbound server.
503Service UnavailableUse when the server is not ready to handle the request, usually due to maintenance or overload. Client retry may be sensible.
504Gateway TimeoutUse when the server, while acting as a gateway or proxy, did not receive a timely response from the upstream server.
505HTTP Version Not SupportedServer does not support the HTTP protocol version used in the request.
507Insufficient StorageServer is unable to store the resource as needed to complete the request. Designed for WebDAV in https://datatracker.ietf.org/doc/html/rfc4918#section-11.5
511Network Authentication RequiredClient needs to authenticate to gain network access.

INFO

💡 For 4xx and 5xx response detail, see Error Design.

References

Design Reference