Every Important HTTP Status Code
Tags: webdev, programming, javascript, tutorial
Published: 2022-12-25 14:53:43

`HTTP` status codes are **three-digit** codes that are used to communicate the status of a request made to a server. They indicate whether the `request` was successful, whether the server needs additional information to complete the request, or whether there was an error. Here is a list of some important HTTP status codes:

## 1xx (Informational)
The first level of status codes is the `100` level. Luckily, these codes are only somewhat common and essential to understanding. These codes indicate that the server has received the request, but has not yet begun to process it. Only some of them apply to normal web development/API development, so we can skip this entire section.

## 2xx (Successful)
200-level of status codes are the most widely used by the web. Luckily there are not many that you need to know. These codes indicate that the request was successful.

### 200 - OK
This code indicates that the request was **successful** and that the requested resource was returned. It is the most common status code and is used when a request is successful and the requested resource is returned in the response.

### 201 - Created
This code indicates that a new resource has been **created** as a result of the request. This might happen when a client submits a `POST` request to create a new resource on the server.

### 202 - Accepted
This code indicates that the request has been **accepted** for processing, but the processing has **NOT** yet been completed. This might happen when a client submits a request that takes a long time to process, such as a request to generate a large report.

### 204 - No Content
This code indicates that the request was **successful**, but the server has **NOT** returned any content in the **response**. This might happen when a client submits a request to delete a resource, and the server responds with a 204 status code to indicate that the resource was successfully deleted.

### 206 - Partial Content
This code indicates that the server has fulfilled the **partial** `GET` request for the resource. This might happen when a client requests a range of bytes from a large resource, and the server returns only the requested range of bytes in the response.

## 3xx (Redirection)
300-level of status codes indicates that the client must take additional action to complete the request. These codes are used when the requested resource has been moved to a new **location** and the client needs to use the new location to access the resource.

### 301 - Moved Permanently
This code indicates that the requested resource has been **permanently** moved to a new location. The client should use the new location to access the resource. The client should also update any **references** to the resource to use the new location.

### 302 - Found
This code indicates that the **requested** resource has **temporarily** moved to a new location. The client should use the new location to access the resource. This status code is often used in conjunction with the **Location header**, which specifies the new location of the resource.

### 303 - See Other
This code indicates that the requested resource can be found at a different `URI`, which is specified in the Location header. The client should use the new `URI` to access the resource.

### 304 - Not Modified
This code indicate that a client's cached copy of a resource is still up to date. It is commonly used with the HTTP caching mechanism, which allows a client to store a copy of a resource on the client's computer and use the cached copy to satisfy future requests for the same resource.

## 4xx (Client Error):
400-level of status code indicates that there was an error in the request made by the client. These codes are used when the client has made a request that the server cannot fulfill, either because the request is invalid or because the client lacks the necessary permissions to access the requested resource.

### 400 - Bad Request
This code indicates that the request was **invalid** or could not be understood by the server. This might happen if the request is missing required parameters, if the request is improperly formatted, or if the server does not support the request method (such as `POST` or `DELETE`).

### 401 - Unauthorized
This code indicates that the client is not **authorized** to access the requested resource. The client must **authenticate** itself to get the requested response. This status code is often used in conjunction with the WWW-Authenticate header, which specifies the **authentication** method that the client should use.

### 403 - Forbidden
This code indicates that the client is not allowed to access the requested resource. This might happen if the client lacks the necessary permissions to access the resource, or if the server has implemented access control measures that prevent the client from accessing the resource.

### 404 - Not Found
This code indicates that the requested resource could not be found on the server. This might happen if the client has requested a resource that does not exist, or if the server is unable to locate the requested resource.

## 5xx - (Server Error)
500-level of status code indicates that there was an **error** on the server while processing the request. These codes are used when the server is unable to fulfill the request due to an unexpected condition or because of a problem with the server itself.

### 500 - Internal Server Error
This code indicates that an unexpected condition was encountered by the server while processing the request. This is a general-purpose error code that can be used when no more specific message is suitable.

### 503 Service Unavailable
This code indicates that the server is currently **unable** to handle the request due to **maintenance** or **overload**. The server might return this code temporarily while it is working to improve the performance of the server.

---

## Conclusion
There may be over 50 HTTP status codes, but only a handful you genuinely need to understand. If you know these status codes, you can create a robust API that will be easy to consume.