HTTP Basics – 10 HTTP status codes you need to know

Let’s take a look at the HTTP status codes.

In this text I’m going to walk through the 10 most common status codes you may see working with HTTP.

I hope it will help you to understand how the HTTP works or refresh your knowledge and help you design better APIs.

What is the status code?

The status code contains 3 digits that have an informational role in helping the client to understand what is the result of the request.

Codes groups

There are 5 groups of HTTP status codes:

  • 1xx – Informational
  • 2xx – Success
  • 3xx – Redirection
  • 4xx – Client Error
  • 5xx – Server Error

200 – OK

Most probably you’ll see it when everything is fine 🙂

The request has been successfully processed by the server.

201 – Created

The 201 code is the indicator of successful resource creation. The response body should contain the created resource.

204 – No Content

Similarly to 201, the 204 code is the indicator of successful resource creation.
The only difference is that it doesn’t contain any additional content in the response body.

301 – Moved Permanently

Used mostly for URL redirections.

Indicates that the target resource has been moved to another URL (available in the Location headers of the response)
You can try curl amazon.com -v on your own and you’ll see it in the response headers.

HTTP/1.1 301 Moved Permanently
(...)
Location: https://amazon.com

The browser will understand the Location header value and will redirect you to the HTTPS-based page.

400 – Bad Request

The server can’t process that request due to client error.

Probably your request contains invalid or inappropriate values.

401 – Unauthorized

The request can’t be processed by the server because of the lack of authentication credentials.

403 – Forbidden

The request can’t be processed by the server which understood the request but refuses to authorize it.

Most commonly, the recognized user has no permissions to perform the action on the server.

This request is often confused with 401, but in the case of 403, the authentication is not the problem and the re-authenticating will make no difference.

404 – Not Found

The server can’t find the requested resource.

You can encounter it when you’re trying to access a dead or incomplete URL.

409 – Conflict

This response code indicates a conflict between the current state of the server and the client request.

It is commonly used when you’re dealing with duplicates.

500 – Internal Server Error

The server can’t process that request due to internal server error. This means the 500 code is returned when the reason is clearly on the server-side.

Conclusion

I’m sure you’ve already seen most of the response codes I briefly described in this text.

The most commonly confused ones are 401 and 403 errors which I will describe in the next text of the Ad fontes series.

Resources

Leave a Reply

Your email address will not be published.