Worse than encountering an error is encountering an “unspecified” error. If you don’t want your REST API to give users a hard time, explain the errors and their reasons clearly. Do not forget to use HTTP status codes while doing this. Standard HTTP status codes will suffice for a general description of almost any error.
HTTP status codes (HTTP response codes) are the codes returned in response to an HTTP request sent from the client to the server where a web page is hosted. When a browser (client) wants to connect to the web page, the server hosting the page returns a response (response) related to the status of the relevant page. In this process, which takes place during each browser-server interaction, the server returns a 3 (digit) numbered description in response. This response is contained in the HTTP response header and is not directly part of the page content.
HTTP codes are divided into different meanings and groups according to the beginning of the first of the 3 digits. If a response starts with code 3, it is part of a routing group. At this point, whether the relevant redirect is permanent, temporary or a security-related redirect is determined in the last number among the 2 numbers that will follow after the number 3.
HTTP Status Classes
- 1xx (100 Code Responses): 1xx HTTP Status codes are responses where the user is notified that the request is in progress on the server side. For example, the HTTP 100 response is the one reporting that the request is currently being processed. This response is transmitted to the browser but not reflected to the user screen.
- 2xx (200-Code Responses): 2xx HTTP Status codes are responses from the browser to the server for the page, reporting that the operation was successful. In HTTP 2xx coded responses, it is reported that the server has successfully responded to the request from the browser and the page can be opened. For example, in http 200 “OK” coded responses, the page can be seen clearly in the user’s browser after the request.
- 3xx (300-Code Responses): 3xx HTTP status codes are responses to inform the server that the request from the browser to the web page has been redirected to a different page. In other words, when a request is sent from the browser for pages with 3xx status codes, the server notifies that the relevant page is redirected to a different page with HTTP 3xx coded responses and redirects the user to the new page.
- 4xx (400-Code Responses): 4xx HTTP status codes are responses where a user-generated error has occurred. In other words, when a response with HTTP 4xx error code is sent to the browser, it is reported that the source of the error is the client, that is, the user. However, the user here should not be perceived as the person who sent the request only from the browser. 4xx HTTP error codes may occur after any action taken on the site hosting the web page.
- 5xx (500 Code Responses): 5xx HTTP status codes are the responses that a server-related error occurred during the request sent from the browser.
HTTP Status Codes List
You can find the most common HTTP response codes in the web world in the list below;
1xx Informative HTTP Status Codes
|HTTP 100 (Continue)||It is the response that the request sent to the server by the user (client) is processed properly and that there is no problem with the request with the HTTP status code. After the HTTP 100 code is sent to the browser & user, the user is expected to continue with the request.|
|HTTP 101 (Switching Protocols)||If the client asks the server to change the protocol and provides notification in the header, the positive response from the server is sent with HTTP 101. With the HTTP 101 response code, it is presented to the browser (client) where the request is made, where the protocol is changed.|
|HTTP 102 (Processing)||The HTTP 102 status code is the response that is reported by the client that the request is being processed by the server. The main purpose of sending this response is to prevent time out of the request sent by the client to the server.|
|HTTP 103 (Early Hints)||The HTTP 103 status code is used to return some response headers before the server responds to the request sent by the client to the server.|
2xx Successful HTTP Status Codes
|HTTP 200 (OK)||The request sent by the client to the server has been answered successfully. Depending on the nature of the request sent to the server, there is optional data in the response sent from the server.|
|HTTP 201 (Created)||The HTTP 201 status code is used when the server successfully responds to the request from the client and creates a suitable new resource for the request.|
|HTTP 202 (Accepted)||It is used when the request sent by the client to the server is accepted by the server, but the request is still being processed on the server side. It is not certain whether the request from the client will be completed after the response returned with the HTTP 202 status code. The request may fail.|
|HTTP 203 (Non-Authoritative Information)||The HTTP 203 status code is sent when the request sent by the client is successfully answered by the server, but the metadata sent from the server has changed while reaching the client. At this point, the response from the server to change while reaching the client is usually experienced in the case of proxy use.|
|HTTP 204 (No Content)||The HTTP 204 status code is used when the request sent by the client has been successfully processed by the server but there is no content to be returned to the client. The user is expected to send a request for old or different content.|
|HTTP 205 (Reset Content)||The HTTP 205 status code is sent when the request sent by the client is answered successfully and the request creates a change in the image of the document (resetting the document, etc.). So, for example, when the user presses the reset button on an HTML document, the HTTP 205 status code is returned in response.|
|HTTP 206 (Partial Content)||If the client (browser) uses range headers in the header section, the HTTP 206 status code is used. When this header is used, the client can pause and continue the document sent from the server as requested. For example; An example of this is when you can stop and start the download file from the server you are making a request to.|
|HTTP 207 (Multi Status)||If an XML Document containing more than one HTTP status code is returned in the response of the server to the request sent by the client, the HTTP 207 status code is used. The data in the sent XML document takes part in different studies independently of the request.|
3xx Redirect HTTP Status Codes
|HTTP 300 (Multiple Choices)||The HTTP 300 status code is used in cases where a large number of different resource returns can be made in response from the server related to the request transmitted by the client to the server. From the resources returned by the server as a response, the client (user) must make a choice. If the server prefers one of these preferable sources, it is specified in the locationheader section.|
|HTTP 301 (Permanent Redirect)||The HTTP 301 status code is sent by the server as a response when the requested web page is completely moved by the client. If the request sent by the user to the server is made as Get or Head, the user (client) is sent directly to the new forwarded URL address.|
|HTTP 302 (Temporary Redirect)||In the event that the requested web page is temporarily moved to a different URL address, the server sends the HTTP 302 status code as a response. With this response, the server sends a message to the client that it should continue to use this URL to reach the resource that it wants to reach. Unlike a 301 redirect, the redirect that occurs here is not considered a valid redirect by search engine bots and pagerank is not transferred. (Accepted provisionally)|
|HTTP 303 (See Others)||If the request forwarded to the server by the client is not possible to getfetched with this URL, the server returns HTTP 303 code in response. When the request from the user about the relevant web page is made with get and the URL cannot be answered by the server with get, the server sends the HTTP 303 code to the client to make a request in a different way or to request a different URL.
The resource requested by the client will be discoverable in request formats like post, delete etc, but if it is not available with Get, HTTP 303 will be returned as a response.
|HTTP 304 (Not Modified)||If the web page or document sent by the client to the server has not undergone any changes since the user’s last connection, an HTTP 304 response code is returned by the server. The main purpose here is to trigger the use of Cache and increase opening speeds by notifying the client of the unmodified documents.|
|HTTP 305 (Use Proxy)||In case the web page requested by the client is viewable only with the proxy (different location header), the server returns the HTTP 305 status code as a response.|
|HTTP 307 ( Temporary Redirect)||If the address sent by the client is found by the server, but broadcasting from a different URL address, an HTTP 307 status code is returned in response. As with the HTTP 302 status code, the server sends this response and sends the message to the client that it should continue to use this URL to reach the requested resource.
The main difference between 302 redirect and 307 is that the form of the request made in 307 and the basic part of the request remain unchanged.
|HTTP 308 (Permanent Redirect)||The HTTP 308 status code is returned by the server as a response to notify that the request sent from the client to the server as an alternative to HTTP 301 has been successfully moved to a different URL. Unlike HTTP 301 redirect, HTTP request method is not allowed to change in HTTP 308 redirect.|
4xx Client Error HTTP Status Codes
|HTTP 400 (Bad Request)||It is the HTTP status code sent when the request sent by the client to the server cannot be answered due to an incorrect request (syntax error).|
|HTTP 401 (Unauthorized)||HTTP 401 status code is returned by the server in order to share the information that the operation related to the requested web page by the client cannot be performed without authorization. In order for the authorization process to be performed, the server informs the client how the authorization can be done by returning the WWW_Authenticate server response header.|
|HTTP 402 (Payment Required)||The information that the user has to pay in order to view the web page requested by the client is reported by the server with the HTTP 402 status code. Generally, it is possible to encounter HTTP 402 error codes on a page to be shown in the next stage or on pages whose usage is limited to certain limits.|
|HTTP 403 (Forbidden)||In cases where the request forwarded by the client to the server is fulfillable by the server, but the client is not authorized to access this resource, the HTTP 403 status code is returned in response. The client is prompted not to repeat the unauthorized request.|
|HTTP 404 (Not Found)||When the server cannot find resources related to the web page requested by the client, it returns an HTTP 404 status code in response. It is the most common mistake in the web world.|
|HTTP 405 (Method Not Allowed)||HTTP 405 status code is used when the HTTP request method (GET or POST) of the request sent by the client is not allowed. Generally, it is encountered in cases where the server recognizes the request method, but the resource to be connected does not allow this method. Likewise, this error code is encountered in cases where request methods that the server does not recognize are used.
|HTTP 406 (Not Acceptable)||In cases where the request sent from the client to the server cannot be served as the request was made (form), HTTP 406 status code is returned by the server as a response. For example, if the client sends a request over a gif format to an image that exists only as png on the server, the server returns HTTP 406 in response to this request.|
|HTTP 407 (Proxy Authentication Required)||Similar to the HTTP 401 request, in the case of the HTTP 407 status code, the server requests verification from the client sending a request for a document. In the case where a proxy is used, the server also requests the proxy’s authorization and asks the client to verify the proxy before connecting.|
|HTTP 408 (Request Timed Out)||If the request sent by the client to the server cannot be completed by the server within the specified time, the HTTP 408 status code is returned as a response.|
|HTTP 409 (Conflict)||In cases where processing the request sent by the client would cause confusion in the requested resource, the server returns the HTTP 409 status code in response.|
|HTTP 410 (Gone)||In cases where the resource requested by the client is permanently deleted from the server and will not be returned, the server returns the HTTP 410 status code in response. In particular, the information that a content is permanently deleted is given to search engines with the HTTP 410 status code.|
|HTTP 411 (Length Header Required)||If the request sent from the client cannot be processed by the server because it does not contain a content-length header, an HTTP 411 status code is returned in response.|
|HTTP 412 (Precondition Failed)||HTTP 412 is returned in response if a condition communicated to the server by the client cannot be met.|
|HTTP 413 (Request Entity Too Large)||In cases where the size of the file request forwarded by the client to the server is too large, the server rejects the operation and returns the HTTP 413 status code in response.|
|HTTP 414 (Requested URL Too Large)||When the URL requested by the client is too large (long), the server sends the HTTP 414 status code as a response. There is no definite limit on URL length due to HTTP standards, but URL size may be limited due to server configuration settings.|
|HTTP 415 (Unsupported Media Type)||In cases where the media type of the file requested by the client is not supported by the server, the HTTP 415 status code is returned in response.|
|HTTP 416 (Requested range not satisfiable)||If part of the resource requested by the client is invalid or unavailable, the server returns the HTTP 416 status code in response. Such situations often appear with partial (progressive) downloads.|
|HTTP 417 (Expectation Failed)||If the server does not meet the conditions in the expect header field in the header of the request sent by the client, it returns the HTTP 417 status code in response.|
|HTTP 421 (Misdirected Request)||When the request sent by the client is forwarded to a server where the response cannot be sent, the HTTP 421 status code is returned in response.|
|HTTP 422 (Unprocessable Entity)||If the request sent by the client to the server contains semantic errors, the server cannot process the request and returns HTTP 422 status code in response.|
|HTTP 423 (Locked)||The information that the resource requested by the client is currently a locked resource is reported by the server with the HTTP 423 status code.|
|HTTP 424 (Failed Dependency)||The server returns the http 424 status code when the resource requested by the client cannot be processed because the previous resource related to the relevant resource could not be processed.|
|HTTP 425 (Too Early)||The HTTP 425 status code is sent as a response when a request to the server is in a replayable state and the server does not want to process the request.|
|HTTP 426 (Upgrade Required)||In case the requesting client needs to upgrade to Transport Layer Security (TLS / 1.0), the HTTP 426 status code is returned in response.|
|HTTP 428 (Precondition Required)||An HTTP 428 status code is returned in response when the server requests conditions to be specified first so that the request sent by the client to the server can be processed.|
|HTTP 429 (Too Many Requests)||When a large number of requests are sent by the client to the server in a limited time, the server returns the HTTP 429 status code in response.|
|HTTP 451 (Unavailable For Legal Reasons)||If the resource the client wants to access is legally blocked in a region or country, the server returns the HTTP 451 status code in response. The reason for this blocking may be copyright, legal ban (blackout) or national blocking.|
5xx Server HTTP Status Codes
|HTTP 500 (Internal Server Error)||When the server is unable to process the request from the client due to an identified internal error, it returns the HTTP 500 status code in response. The server may not be able to process the request for reasons such as errors in the programs on the server, database errors.|
|HTTP 501 (Not Implemented)||The HTTP 501 status code is a response code returned by the server for an error that occurs when the server does not have functions to handle the request from the client. This problem is usually caused by the web host and is solved by the web host (hosting provider).|
|HTTP 502 (Bad Gateway)||In cases where a proxy is used, an HTTP 502 status code is sent to the client in response when one of the servers providing the data streams returns an incomprehensible response code to the other.|
|HTTP 503 (Service Unavailable)||Whenever the server service is unavailable, the server returns an HTTP 503 response to the client. It is usually seen in sites that receive a lot of traffic, after heavy data transfer, in cases where the server swells or the server is taken into maintenance. It can also be seen on small and medium-sized sites if your server is not capable of handling your site’s traffic.|
|HTTP 504 (Gateway Time-out)||In the case of a connection using a proxy, the HTTP 504 status code is returned to the client as a response, in case the proxy server cannot process the request due to timeout.|
|HTTP 505 (HTTP Version Not Supported)||An HTTP 505 status code is returned in response when the HTTP version the request is sent to is not supported.|
|HTTP 507 (Insufficient Storage)||When the request from the client to the server cannot be processed due to insufficient storage space of the server on the server side, the server returns an HTTP 507 status code in response.|
|HTTP 509 (Bandwidth Limit Exceeded)||When a client-to-server request is rejected because it would fill the server’s traffic bandwidth if processed, the server returns the HTTP 509 status code in response.|
|HTTP 511 (Network Authentication Required)||The HTTP 511 status code is returned in response when the client must first authenticate before it can establish a connection to the network.|
|HTTP 521 (Web Server is Down)||The HTTP 521 error is a status code for websites using cloudflare. An HTTP 521 error code is returned in response when the client (browser) establishes a healthy connection to Cloudflare, but Cloudflare cannot connect to the server of the web page. Here, it is reported via cloudflare that the server where the requested web page is located is not responding.|
HTTP status codes play a vital role for both developers and users of an application. It gives a clear understanding and direction about the current state of things on a web page. It also helps with search engine optimization and digital marketing.