HTTP Status Codes
Udara Abeythilake
Mobile App Developer at PixelForce(Android , Flutter, React-Native)
What are HTTP status codes?
HTTP status codes are the codes used by the server to send the response to the client side indicating the status of the client request (most probably web browsers). When a request has been sent by the client to the server, the server should be responsible for giving something back to the client with a status. That request made by the client side may be failed or be successful, but to keep the proper communication between the client and the server we used to add status for every response generated by the server. Usually, HTTP status codes are with a 3-digit number
We can categorize the HTTP status codes as below
Informational responses
100 Continue
The 100-status code indicates that the initial part of the request has been received and has not been rejected by the server. The client should continue by sending the remainder of the request or, if the request has already been completed, ignore the response
101 Switching Protocols
This response code indicates a protocol to which the server switches. The protocol is specified in the?upgrade?request header received from the client.
What is an upgrade?
It is a field in the HTTP header which is used to upgrade the existing client/server connection to a different protocol
Example:
Upgrade field of the header can be used to upgrade from HTTP 1.1 to HTTP 2.0, or an HTTP or HTTPS connection into Web Socket
102 Processing
This status code indicates that the server has received and is processing the request, but no response is available yet. This status code is only sent when the server has a reasonable expectation that the request will take significant time to complete. As an example, if functionality takes more than 20 seconds to complete the process the server should return status code 102 as a response. Then the server must send the final response after the request process is completed
103 Early Hints
The HTTP 103 Early Hints information response status code is primarily intended to be used with the?Link?header to allow the user agent to start preloading resources while the server is still preparing a response.
What is a Link header?
The HTTP Link entity-header field provides a means for serializing one or more links in HTTP headers. It is semantically equivalent to the HTML <link> element.
Successful responses
200 OK
The status code indicates the request has been successfully executed on the server
201 Created
This status code will indicate that the request is successfully executed and created a new resource. For example, if a request has been made by the client to register, the user server will process that request and create a user in the database and return the 201-status code as the user created.
202 Accepted
Indicates that the request has been received but not completed yet. It is typically used in log running requests and batch processing.
203 Non-Authoritative Information
The HTTP 203 Non-Authoritative Information response status indicates that the request was successful but the enclosed payload has been modified by a transforming proxy from that of the origin server’s 200 (OK) response
What is a proxy?
A proxy server is an intermediate program or computer used when navigating through different networks on the internet. They facilitate access to content on the World Wide Web. A proxy intercepts requests and serves back responses
204 No Content
The HTTP 204 No Content success status response code indicates that a request has succeeded, but that the client doesn’t need to navigate away from its current page. This might be used, for example, when implementing the “save and continue editing” functionality for a wiki site. In this case, a PUT request would be used to save the page, and the 204 No Content response would be sent to indicate that the editor should not be replaced by some other page.
205 Reset Content
The HTTP 205 Reset Content response status tells the client to reset the document view, so for example to clear the content of a form, reset a canvas state, or to refresh the UI.
206 Partial Content
The HTTP 206 Partial Content success status response code indicates that the request has succeeded and the body contains the requested ranges of data, as described in the Range header of the request.
If there is only one range, the Content-Type of the whole response is set to the type of the document, and a Content-Range is provided.
If several ranges are sent back, the Content-Type is set to multipart/byteranges and each fragment covers one range, with Content-Range and Content-Type describing it.
Redirection messages
300 Multiple Choices
This status code indicates that the request has more than one possible response. The user-agent or the user should choose one of them. As there is no standardized method for choosing the response, this response code is very rarely used
301 Moved Permanently
This status code indicates that the requested resource has been permanently moved to a new URL provided by the?Location?header in the response. Browser redirects to the new URL and search engines update their links to the resource.
What is the Location header?
The Location response header indicates the URL to redirect a page to, this header is useful in response codes 301, 302 or 201
302 Found
This status response code indicates that the resource requested has been temporarily moved to the URL given by the Location header. A browser redirects to this page but search engines don’t update their links to the resource
303 See Other
This status code indicates that the redirects don’t link to the requested resource itself, but to another page (such as a confirmation page, a representation of a real-world object, or an upload-progress page). This response code is often sent back as a result of PUT or POST. The method used to display this redirected page is always GET.
304 Not Modified
An HTTP 304 not modified status code means that the website you’re requesting hasn’t been updated since the last time you accessed it. Typically, your browser will save (or cache) web pages so it doesn’t have to repeatedly download the same information. This is an attempt to speed up page delivery.
307 Temporary Redirect
This status code indicates that the URL the user is requesting has been temporarily transferred to a location and will be back soon
308 Permanent redirect
This status response code indicates that the resource requested has been definitively moved to the URL given by the Location headers. A browser redirects to this page and search engines update their links to the resource
Client error responses
400 Bad Request
This status code indicates that the server cannot or will not process the request due to something bad data or a bad request from the client side (for example, malformed request syntax, invalid request message framing, or deceptive request routing).
领英推荐
401 Unauthorized
This status code indicates that the client is not authenticated. This status code can be received if the authentication credentials are not passed with the request header
402 Payment Required
The HTTP 402 Payment Required is a nonstandard response status code that is reserved for future use. This status code was created to enable digital cash or (micro) payment systems and would indicate that the requested content is not available until the client makes a payment.
403 Forbidden
This status code indicates that the server identifies the request, but refuses to authorize it. This is similar to the 401 status code, but in this status, code re-authenticating makes no difference
404 Not Found
This status code indicates that the server cannot find the requested resources.
405 Method Not Allowed
This status code indicates that the server knows the requested method but the target resource does not support this method.
406 Not Acceptable
This status code indicates that the server cannot produce a response matching the list of acceptable values defined in the request’s proactive content negotiation headers and that the server is unwilling to supply a default representation.
407 Proxy Authentication Required
This status code indicates that the request cannot be applied due to a lack of valid authentication credentials for a proxy server that is between the browser and the server that can access the requested resources. This status is sent with a Proxy-Authenticate header that contains information on how to authorize correctly
408 Request Timeout
This status code indicates that the server would like to shut down the unused connection. It is sent on an idle connection by some servers even without any previous request by the client
409 Conflict
This status code indicates that the request could not be processed because of conflict in the request, such as the requested resource is not in the expected state, or the result of processing the request would create a conflict within the resource.
410 Gone
This status code indicates that access to the target resource is no longer available at the origin server and that this condition is likely to be permanent. This is similar to the 404 status code.
411 Length Required
This status code indicates that the server refuses to accept the request without a defined Content-Length header.
What is the Content-Length header?
The Content-Length header indicates the size of the message body, in bytes, sent to the recipients
412 Precondition Failed
This response code allows the client to place preconditions on the current resource state (its current representations and metadata) and, thus, prevent the request method from being applied if the target resource is in an unexpected state.
413 Payload Too Large
This status code indicates that the request entity is larger than the limits defined by the server. In this situation, the server will close the connection or return a Retry-After header field
414 Uri Too Long
This status code indicates that the URI requested by the client is longer than the server is willing to interpret.
415 Unsupported Media Type
This status code indicates that the server refuses to accept requests because the payload is an unsupported format
416 Requested Range Not Satisfiable
This status code indicates that a server cannot serve the requested ranges. The most likely reason is that the document doesn’t contain such ranges, or that the?Range?header value, though syntactically correct, doesn’t make sense.
What is a Range header?
The Range header indicates the part of a document that the server should return.
417 Expectation Failed
This status code indicates that the expectation given in the request?Expect?header could not be met
What is the Expect header?
The expect header indicates the expectation that needs to be met by the server in order to handle the request successfully
422 Unprocessable Entity
This status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.
424 Failed Dependency
This status code indicates that the method could not be performed on the resource because the requested action depended on another action and that action failed.
Example:
if a command in a PROPPATCH method fails, then, at minimum, the rest of the commands will also fail with 424
428 Precondition Required
This status code indicates that the origin server requires the request to be conditional. This means that the required precondition header such as If-Match is missing.
429 Too Many Requests
This status code indicates that the client has sent too many requests in a given amount of time. Retry-After header might be included in this response to indicate how long to wait before making a new request.
Server error responses
500 Internal Server Error
This status code indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.
501 Not Implemented
This status code indicates that the server does not support the functionality required by the request. 501 is the appropriate response when the server does not recognize the request method and is incapable of supporting it for any resources.
502 Bad Gateway
This status code indicates that the server while acting as a gateway or proxy, received an invalid response from the upstream server.
503 Service Unavailable
This status code indicates that the server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded. This response should be used for temporary conditions and the Retry-After HTTP header should, if possible, contain the estimated time for the recovery of the service.
504 GATEWAY TIMEOUT
This status code indicates that the server while acting as a gateway or proxy, did not get a response in time from the upstream server that is needed in order to complete the request.
505 HTTP Version Not Supported
This status code indicates that the HTTP version used in the request is not supported by the server.