Decoding HTTP Status Codes: A Developer’s Guide to Understanding API Responses

Harsh Patel
5 min readMar 13, 2024

--

API Status Codes

As a tech enthusiast, we all know what is REST Apis and how it is used. But have you ever wondered about a very common key named STATUS which contains different codes based on API needs?

These status codes are not related to any technology or programming language. This will remain the same for all backend technologies which are used to create REST APIs.

All status codes can be grouped into 5 majors as

  • Informational Response (100–199)
  • Successful Response (200–299)
  • Redirection Response/Messages (300–399)
  • Client Error Response (400–499)
  • Server Error Response (500–599)

Above above-listed status codes are most common in use. There might be other codes available as per the requirements of APIs. Let’s discuss this in detail one by one.

Informational Response

HTTP status codes starting with “1xx” are informational status codes. These codes are typically used by the server to communicate that the request has been received and is being processed. They don’t necessarily indicate success or failure but serve as interim responses while the server continues to process the request.

Some well-known status codes of the 1xx group :

  • 100 (Continue): This interim response indicates that the client should continue the request or ignore the response if the request is already finished.
  • 101 (Switching Protocols): This code is sent in response to an Upgrade request header from the client and indicates the protocol the server is switching to.
  • 102 (Processing): This code indicates that the server has received and is processing the request, but no response is available yet.
  • 103 (Early Hints): This status code is primarily intended to be used with the Link header, letting the user agent start preloading resources while the server prepares a response.

Successful Response

HTTP status codes starting with “2xx” are success status codes. This class of status codes indicates the action requested by the client was received, understood, and accepted.

Some well-known status codes of the 2xx group :

  • 200 (OK): This status code indicates a successful request. It is typically used for GET, PUT, POST, or DELETE requests when the operation is completed successfully.
  • 201 (Created): The request succeeded, and a new resource was created as a result. This is typically the response sent after POST requests or some PUT requests.
  • 202 (Accepted): The request has been received but not yet acted upon. It is noncommittal since there is no way in HTTP to later send an asynchronous response indicating the outcome of the request. It is intended for cases where another process or server handles the request, or for batch processing.
  • 204 (No Content): This status code is used when the server successfully processes a request but does not return any content in the response payload. It is commonly used for DELETE or PUT requests.

Redirection Response/Messages

HTTP status codes starting with “3xx” are redirection status codes. They indicate that further action needs to be taken by the client to complete the request. These codes are often used when a resource has been moved to a different location, and the client needs to take appropriate action to retrieve it.

Some well-known status codes of the 3xx group :

  • 300 (Multiple Choices): The request has more than one possible response. The user agent or user should choose one of them.
  • 301 (Moved Permanently): The URL of the requested resource has been changed permanently. The new URL is given in the response.
  • 302 (Found): This response code means that the URI of the requested resource has been changed temporarily. Further changes in the URI might be made in the future. Therefore, this same URI should be used by the client in future requests.
  • 304 (Not Modified): This is used for caching purposes. It tells the client that the response has not been modified, so the client can continue to use the same cached version of the response.

Client Error Response

HTTP status codes starting with “4xx” are client error responses. These status codes indicate that there was an issue with the client’s request, whether it was due to a client-side error, such as incorrect syntax or authentication problems, or the client requesting a resource that does not exist or is not accessible.

Some well-known status codes of the 4xx group :

  • 400 (Multiple Choices): The server cannot or will not process the request due to something that is perceived to be a client error.
  • 401 (Unauthorized): Although the HTTP standard specifies “unauthorized”, semantically this response means “unauthenticated”.
  • 403 (Forbidden): The client does not have access rights to the content; that is, it is unauthorized, so the server is refusing to give the requested resource. Unlike 401 Unauthorized, the client’s identity is known to the server.
  • 404 (Not Found): The server cannot find the requested resource. In the browser, this means the URL is not recognized. In an API, this can also mean that the endpoint is valid but the resource itself does not exist.

Server Error Response

HTTP status codes starting with “5xx” are server error responses. These codes are sent by the server to indicate that it encountered an unexpected condition that prevented it from fulfilling the request made by the client. When a client receives a 5xx status code, it typically implies that there is an issue on the server side, rather than with the client’s request.

Some well-known status codes of the 5xx group :

  • 500 (Internal Server Error): The server has encountered a situation it does not know how to handle.
  • 501 (Not Implemented): The request method is not supported by the server and cannot be handled. The only methods that servers are required to support (and therefore that must not return this code) are GET and HEAD.
  • 502 (Bad Gateway): This error response means that the server while working as a gateway to get a response needed to handle the request, got an invalid response.
  • 503 (Service Unavailable): The server is not ready to handle the request. Common causes are a server that is down for maintenance or that is overloaded.
  • 504 (Gateway Timeout): This error response is given when the server is acting as a gateway and cannot get a response in time.

Conclusion:

As a Techy bug, we should at least know what we are catching and what it means to the system that we are building. I have tried to cover almost all status codes that are mainly used in development. although there are lot more stuff related to the status code which you can refer to from MDN web docs.

Feel free to raise any question you have in your head and I will try to get your answer best of my knowledge.

And if you like to read more of such articles and want to become part of a great tech journey, please do me a favor, Hit Like to the article, and share it as much as you can !!

--

--