Status Codes
If you've ever consumed and/or created any sort of RESTful service, then you will have encountered various HTTP status codes in the response. Many developers do not have very good knowledge in such a foundational area, probably because there are just way too many that it becomes overwhelming at times. The official standards and list of HTTP codes can be found here (Standard - IETF RFC 7231 and Additional - IETF RFC 6585).
In this section we are going to go over what the big categories of HTTP status codes are. More importantly, we will cover only the most important and commonly used status codes and some guidelines on when/how to use them appropriately.
Brief Overview of the Categories
There are essentially 5 categories of HTTP status codes, and each can be summarized in one sentence.
1xx (Informational): The request was received, continue processing.
2xx (Successful): The request was successfully received, understood, and accepted.
3xx (Redirection): Further action needs to be taken in order to complete the request.
4xx (Client Error): The request from the client cannot be fulfilled due to malformed inputs.
5xx (Server Error): The server failed to fulfill a valid request from the client.
For the full list, head over to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status.
100 – 199 (Informational) Guidelines
In the context of creating APIs, this can be ignored. To learn more, head over to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#information_responses.
200 - 299 (Successful) Guidelines
The 200s status codes generally tell the client that the request was successful. This is usually used with either a POST or PUT request, or any time a user is creating something. There are a ton of rarely used 200 status codes, below is a list of the most used ones.
300 - 399 (Redirection) Guidelines
The 300s are not particularly important in the context of creating RESTful APIs, because their main importance are in the field of SEO. However, below are a couple that are quite important to know and understand.
400 - 499 (Client error) Guidelines
The 400s are probably the most important out of all the other categories. These are the ones that the client calling your API has to interact with. Imagine these status codes as a way of providing form validation and signaling to the client what is right or wrong. The 400 category contains the most out of any of the other categories, there are over 30 different 400 status codes. Below are the most commonly used ones that you must know.
500 - 599 (Server error) Guidelines
Finally, the 500 status codes. Most of the time, a general 500 error is enough to indicate to the client what is going on. I am not going to stress too much about the 500 errors, it is beyond the scope of this book. You can read more about it on MDN: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses.
Last updated