In this document we have listed the Http status codes cheat sheet which are used most commonly by any kind of client server applications and will be helpful for our node.js learning process.
What is a Http status code?
HTTP status codes are numerical codes sent by a web server in response to a request made by a web browser or any kind of client application. These codes are used to inform the web browser or the client application about the outcome of the corresponding request.
Considering the request response cycle as mentioned in the previous article, we made requests to the web server and received a response for the same. So in this case there are varied types of response that the webserver sends as a response which basically contains the information about whether the request succeeded or failed.
Types of Http request
GET – The Get method retrieves information from the web server that hosts a website’s content. It allows users to receive the data which they request from the websites. The Get method is identical to a read query. The Get request is the most common request made by the web browsers when we type in a url to visit a website.
POST– Post is an HTTP request that can send data to our backend web server to add or update a particular entry. We can use this request to update or add data to a database or server, depending on the situation. The Post method sends form data using the request body. It can be used to send data to your server. Key features of a POST method are –
- Data sent using the POST method is not visible in the URL on the browser.
- Additionally, data sent through POST is not saved in browser history, and would not appear in any other websites unless it were included as part of the URL.
- Using POST, one can also send strings and binary data of varying lengths, as well as different data types i.e. integers, floats, booleans.
HEAD – Head method is similar to the Get method. It retrieves data only from a file’s header. We use this method when we need to retrieve file size without downloading the file and also we use this method to know about the file type and content type. Considering that we are about to download a file from any website the head method will provide the user with the kind of file i.e, pdf or exe or jpg or dmg, the size of the file in Kb or Mb etc and also other related information.
PUT – The PUT method updates the data into the web server. The main difference is that we use PUT when we have to replace an existing data completely. Things such as updating your phone number, email address in services such as gmail, facebook etc.
DELETE– This method deletes the user specified data through a generated specific URL. Similarly to the Get method, the body of the request does not contain any data.
PATCH – This is similar to the Post and Put methods but we often use this methods when we have to update some of the data partially and not replace/overwrite the data completely.
List of http status codes
The following is a List of http status codes describing commonly used status code numbers and their respective status codes.
HTTP Status code 1xx
HTTP Status Code 100 – Continue
The status codes containing the 1xx or the numbers in the 100’s. The 100 response code indicates a successful transaction. The request was received by the server and successfully completed. The client should continue with the request and is expected to process the response (unless there is a redirect from the server).
HTTP STATUS CODE 101 – SWITCHED PROTOCOL
The 101 response code indicates that the client has switched to a different protocol. The client is then expected to process the response. The server has received your browser’s request header and is now awaiting for the body of your request. However, due to the change in protocol, the request has been redirected to a different server and the new URL and response headers are now being sent to the browser. The response code is set to 100 because the browser is now able to make a new request with the new URL.
HTTP STATUS CODE 102 – PROGRESS.
The 102 response code indicates progress has been made in the request but there isn’t any valid response available to be provided by the server yet.
The server has received your browser’s request header and is now awaiting for the body of your request. However, the server has not yet completed processing the request. The response code is set to 100 because the browser is now able to make a new request with the new URL.
HTTP STATUS CODE 103 – Early hints.
The server has received your browser’s request header and is now awaiting for the body of your request.
HTTP Status code 2xx
The status codes containing the 2xx or the numbers in the 200’s. The 2xx status codes indicate successful completion of the request.A 2xx status code indicates that the request method was successfully applied to the resource identified by the Request-URL. These response codes typically suggests the user directed actions and requests to the web server are successfully executed/served.
Some of the important 2xx codes are –
Http status code 200 – Success/ Response OK
The 200 OK status code indicates that the request was handled successfully. This code is used for all standard web requests. For example, a request for a plain text file might return 200 OK, and a request for an image file might return 200 OK.
Http status code 201 – Created
The 201 response codes means that the requested program caused the indicated resource to be produced. For example when a user is signing up to an email account, if the user’s data is successfully received by the server and a file for the user account has been created containing the user profile.
Http status code 202 – Accepted
This status code does not offer a guarantee that the request has been completely processed. A processing might or might not be done, but it does not prioritise processing before other work. The processing could take place and could complete afterwards, but it is unknown if it will be done at all.
Http status code 203 – Non authoritative information
This status code is defined as non-authoritative information or a non-repudiated response, means that the server is willing to accept the information and respond in conformity with the latest version of the entity.
Http status code 204 – No Content
The most common HTTP response code, is sent with a request when the server is unable to respond or doesn’t has any kind of response data, although the request has been processed, but is fine to allow the user agent to update its caches for the resultant response. This is typically returned after the DELETE request where a specific user requested data was deleted from the server successfully.
Http status code 205 – Reset Content
Reset Content status code means that the person behind this message should reset the document/query/request.
Http status code 206 – Partial content
This status code means “The response is specifically limited to its representation(s) of a part of the requested resource.” This clearly means that a specific part of the complete resource was provided to the client and that the whole content was not provided.
Http status code 207 – Multi Status
The Multi-status code tells information that there are multiple responses applicable for this specific request made by the user. Typically multiple status codes would have been returned for a specific kind of request.
The 3xx Http status codes
The status codes containing the 3xx or the numbers in the 300’s – A 3xx Redirect status code means that your webpage had been redirected and the completion of the request requires further action, such as a redirecting you to an alternate or new landing page, email, or message pop up. These were the natural steps of interacting with websites in early 2000s.
A 3xx redirection means that the request was successfully received, the domain or the requested page or resource was actually found (independent of the 3xxRedirect location path provided in the codes) and the client only needed to reach to a new location/resource/page instead of the current version of the webpage which was requested. Ultimately the request will end in a 2xx success response, but it has been made to be passed through the message indicating a redirection.
Some of the important 3xx codes are –
Http status code 301 – Moved Permanently
If a website sends a 301 Moved Permanently response, it indicates that the specified page or resource has been moved permanently to a new address and any future references should be made to the new address, not the original or the current one.
Http status code 302 – Found
This status code is for ensuring that the URL you want to use in future requests can also be used, so you need to check that it is still the URL you want to use. The code has three parts: the HTTP status code (302), the effective request URL, and a reason phrase telling you what is the new URL.
Http status Status code 304 – Not Modified
This also tells the server that the original response hasn’t been changed and by knowing this the server doesn’t needs to send back the same data which was already requested by the client previously. This lets the client continue to use the cached version of the response which is already cached in their browser or application.
Http status code 307 – Temporary redirect
Sometimes it happens that the resource which is requested by the client is temporarily redirected to another URL but is containing the original resource. In such cases client is asked that it should use the original URL only and this redirection to the new URL is a temporary action. The browser, however, keeps the original request method though in this case.
Http status code 308 – Permanent Redirect
This status code tells that the user agent’s/client’s origin receives a different URL other than the requested URL. The user agent cannot then again request for the current URL again. Practices such as wrong password re-use may lead to unwarranted redirection.
Http 4xx Response codes
The status codes containing the 4xx or the numbers in the 400’s. A 4xx Client Error status code means that the website or the page could not be reached and either the page is unavailable or the request contains bad syntax or wrong parameters. Some of the important 4xx codes are –
Http status code 400 – Bad Request
This is usually caused by either the client using an invalid HTTP request header or an invalid body, or the server receiving an invalid HTTP request message and client’s identity is also not been verified.
Http status code 401 – Unauthorized
this status code means that the request could not be processed because the server requires it to be authenticated by the user. Typically if you enter a wrong username or password to access any kind of account or resource, this status code is returned by the server.
Http status code 403 – Forbidden
This status code is thrown to stop web traffic from the web server to the clients making a request to access a resource which they don’t have right to access. The client’s URL is rejected because the client does not have rights to view the content requested to the server.
Http status code 404 – Not Found
This status code means that the server either does not have a current representation of a specific resource, or it is not trying to expose it to the requested client. Thereby, such a device has been deemed to be non-existent. In this case the client’ requested resource/page cannot be found the server.
Http status code 408 – Request Timeout
Server expresses that it did not receive a complete request in a desired timeframe. Requests may be retried as a result of this.
The status codes containing the 5xx or the numbers in the 500’s. This server error means that while the request looks valid, the server had a problem responding to it. If this is happening for you, you should first try to troubleshoot the problem on the server.
Some of the important 5xx codes are –
Http status code 500 – Internal Server Error
This happens when the server encountered a situation when it does not know how to handle the current request. Typically an unknown kind of request has been made by the client which the server is unable to determine.
Http status code 501 – Not Implemented
This message means that the request cannot be handled because the server is unable to process such requests. This is similar to the 500 error and the main difference is although the server can recognise what kind of data was requested, such requests too cannot be processed by the server.
Http status code 502 – Bad Gateway
The server received a bad or incorrect response while serving as a gateway to process the request.
Http status code 503 – Service Unavailable
This indicates that the server is not capable or not available to process the requests because it is busy updating, creating, or managing data. This occurs when the server is down for maintenance or is overloaded.
Http status code 504 – Gateway Timeout response code
This indicates that the server which is working as a gateway could not get a response from the gateway within the stipulated time frame.