DEV Community

Cover image for Web Services 101: Why x00 status codes are so generic

Posted on

Web Services 101: Why x00 status codes are so generic

Photo by from Pexels

Quick intro to HTTP status codes

HTTP status codes are sent in every HTTP response to indicate the result of servicing the request.

They are arranged into categories by 100's, as follows:

Code range Meaning
200-299 Success
300-399 Redirection
400-499 Client error
500-599 Server error

A useful reference to bookmark is

x00 status codes

Now let's look closer at the definition of each x00 status code.

Code Meaning
200 OK
300 Multiple Choices
400 Bad Request
500 Internal Server Error

Why do you think these are so generic like "Bad Request," "OK," or the even more vague "Multiple Choices?"


The vagueness is on purpose. These codes are supposed to cover all possibilities. The HTTP specification describes them as the "stand in" codes for those situations where a custom HTTP status code has been defined by the service, and the client needs to interpret the response anyway.

HTTP status codes are extensible. HTTP applications are not required to understand the meaning of all registered status codes, though such understanding is obviously desirable. However, applications MUST understand the class of any status code, as indicated by the first digit, and treat any unrecognized response as being equivalent to the x00 status code of that class...



So we can conclude two things.

First: we can create our own custom HTTP status codes. Maybe we want to pick the unused status code 442 and define it as "<SomeProperty> is required." That's totally fine.

Second: we can also conclude that our clients will interpret our custom HTTP status codes as their x00 counterpart. For the given example of 442, clients will assume this is equivalent to 400 "Bad Request."

Discussion (0)