Activity #30: HTTP Status Codes

HTTP status codes used in RESTful APIs
HTTP, which stands for Hypertext Transfer Protocol, is the foundation of any data exchange on the web. In simple terms, it's the language that web servers and clients (like your web browser) use to communicate with each other.
An HTTP status code, as the name implies, is a three-digit code that a server sends in response to a client's request. The HTTP code indicates whether the request was successful or if there were any errors.
HTTP status codes play a critical role in REST APIs as they provide a way for the server to communicate the outcome of an API request to the client. They allow the client to understand the status of the requested operation and take appropriate action based on the response received.
These status codes, often referred to as response status codes, serve as a means of communication between the server and the internet browser and there are multiple code classes based on the type of information they are communicating.
1xx (Informational)
A 1xx Informational status code means that the server has received the request and is continuing the process. A 1xx status code is purely temporary and is given while the request processing continues. For most tasks you won't encounter these much, as it's not the final response to the request.
2xx (Success)
A 2xx Succesful status code means that the request was successful and the browser has received the expected information. This is generally the one you want to see, as it means that the request was a success and has been received, understood and accepted it. As a website owner you should make sure that all pages and resources (images, videos, etc.) all return a 2xx status code. This means that browsers can reach it successfully and that your website visitors can see and use your website.
200 OK: Indicates that the request has succeeded.
201 Created: Indicates that the request has succeeded and a new resource has been created as a result.
204 No Content: The server has fulfilled the request but does not need to return a response body. The server may return the updated meta information.
3xx (Redirection)
A 3xx Redirection status code means that you have been redirected and the completion of the request requires further action. Redirects are a natural part of the internet and you shouldn't be scared to have 3xx redirect status codes on your website. A redirect means that the request was received successfully, but that the resource was found elsewhere. If a webpage has changed path and you try to access it through the old path, your CMS will often redirect the user to the new path. Ultimately the request will end in a 2xx success, but first it must go through the 3xx redirection.
4xx (Client Error)
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. As a website owner you should do your best to avoid these, as it means your users will not find what they're looking for. This can be either pages that are no longer found and are either temporarily or permanently gone. Besides giving a bad user experience, it can also hurt your SEO efforts.
400 Bad Request: The server could not understand the request due to incorrect syntax. The client should NOT repeat the request without modifications.
401 Unauthorized: Indicates that the request requires user authentication information. The client MAY repeat the request with a suitable Authorization header field
403 Forbidden: Unauthorized request. The client does not have access rights to the content. Unlike 401, the client’s identity is known to the server.
404 Not Found: The server can not find the requested resource.
5xx (Server Error)
A 5xx Server error status code means that while the request appears to be valid, the server could not complete the request. If you're experiencing 5xx server errors for your website, you should immediately look at your server. If you're hosting your own server you'll need to start debugging to figure out why it is not responding properly. If you're using an external hosting provider you'll need to reach out to them, so they can look at it.
500 Internal Server Error: The server encountered an unexpected condition that prevented it from fulfilling the request.
503 Service Unavailable: The server cannot handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay. If known, the length of the delay may be indicated in an associated Retry-After header field.
References:
https://seomator.com/blog/common-http-status-codes
https://umbraco.com/knowledge-base/http-status-codes/#503-service-unavailable
