Rest API Status Codes
What is Status Code
When we make a request to the server, the server sends back a response with a status code. This status code is a three-digit number that indicates the different status of the request. The status code is a part of the HTTP protocol. The status code is divided into five categories. The categories are:- 1xx - Informational - status code that starts with 1 represents the request is received and the process is continuing.
- 2xx - Success - status code that starts with 2 represents the request is successfully received, understood, and accepted.
- 3xx - Redirection - status code that starts with 3 represents the further action is needed to complete the request.
- 4xx - Client Error - status code that starts with 4 represents the request contains incorrect syntax or cannot be fulfilled.
- 5xx - Server Error - status code that starts with 5 represents the server failed to fulfill a valid request.
Common Status Codes
Here are some of the common status codes that we see while working with Rest API in day-to-day scenarios:Status Code | Status | Description |
---|---|---|
200 | OK | Request is successful and the response contains the requested data. |
201 | Created | Request is successful and a new resource is created. |
204 | No Content | Request is successful but the response contains no content. |
400 | Bad Request | Request contains invalid input data or the request is malformed, hence cannot be processed. |
401 | Unauthorized | Request is unauthorized and we need to provide valid credentials. |
403 | Forbidden | Request is forbidden that mean we are not allowed to perform any action on the resource. |
404 | Not Found | Resource is not found |
500 | Internal Server Error | Server failed to fulfill a valid request due to an error on the server side. |
1xx status codes are Informational status codes. We generally do not see these status codes in day-to-day scenarios. Here are some of the 1xx status codes:
Status Code | Status | Description |
---|---|---|
100 | Continue | The server has received the request headers and the client should proceed to send the request body. |
101 | Switching Protocols | The requester has asked the server to switch protocols and the server has agreed. |
102 | Processing | The server has received and is processing the request, but no response is available yet. |
103 | Early Hints | Used to return some response headers before final HTTP message. |
104 | Unavailable For Legal Reasons | The server is denying access to the resource as a consequence of a legal demand. |
105 | Request Header Too Large | The server is refusing to process a request because the request header fields are too large. |
106 | SSL Certificate Error | Used to return some response headers before final HTTP message. |
107 | HTTP Version Not Supported | The server does not support the HTTP protocol version used in the request. |
108 | Network Authentication Required | The client needs to authenticate to gain network access. |
109 | Origin Error | Used to return some response headers before final HTTP message. |
110 | Connection Timed Out | The server is timing out the connection. |
2xx status codes are Success status codes. These status codes indicate that the request was received, understood, and accepted successfully. Here are some of the 2xx status codes:
Status Code | Status | Description |
---|---|---|
200 | OK | Request is successful and the response contains the requested data. |
201 | Created | Request is successful and a new resource is created. |
202 | Accepted | Request is accepted for processing but the processing is not completed. |
203 | Non-Authoritative Information | Request is successful but the response is from a third-party server. |
204 | No Content | Request is successful but the response contains no content. |
205 | Reset Content | Request is successful and the client should reset the document view. |
206 | Partial Content | Request is successful and the response contains only part of the requested data. |
207 | Multi-Status | Used in WebDAV to indicate multiple status codes for a single response. |
208 | Already Reported | Used inside a DAV: propstat response element to avoid enumerating the internal members of multiple bindings to the same collection repeatedly. |
226 | IM Used | The server has fulfilled a GET request for the resource and the response is a representation of the result of one or more instance-manipulations applied to the current instance. |
3xx status codes are Redirection status codes. These status codes indicate that further action is needed to complete the request. Here are some of the 3xx status codes:
Status Code | Status | Description |
---|---|---|
300 | Multiple Choices | Indicates multiple options for the resource from which the client may choose. |
301 | Moved Permanently | This and all future requests should be directed to the given URI. |
302 | Found | Tells the client to look at another URL. |
303 | See Other | Tells the client to look at another URL. |
304 | Not Modified | Indicates that the resource has not been modified since the version specified by the request headers. |
305 | Use Proxy | The requested resource is available only through a proxy, the address for which is provided in the response. |
306 | Switch Proxy | No longer used. |
307 | Temporary Redirect | Tells the client to look at another URL, but do not change the method of the request. |
308 | Permanent Redirect | The request and all future requests should be repeated using another URI. |
309 | Resume Incomplete | Used in the resumable requests proposal to resume aborted PUT or POST requests. |
310 | Too Many Redirects | The user-agent has sent too many requests in a given amount of time. |
4xx status codes are Client Error status codes. These status codes indicate that the request contains incorrect syntax or cannot be fulfilled. Here are some of the 4xx status codes:
Status Code | Status | Description |
---|---|---|
400 | Bad Request | Request contains invalid input data or the request is malformed, hence cannot be processed. |
401 | Unauthorized | Request is unauthorized and we need to provide valid credentials. |
402 | Payment Required | Reserved for future use. |
403 | Forbidden | Request is forbidden that mean we are not allowed to perform any action on the resource. |
404 | Not Found | Resource is not found |
405 | Method Not Allowed | The method specified in the request is not allowed for the resource identified by the request URI. |
406 | Not Acceptable | The server cannot generate a response that the client will accept. |
407 | Proxy Authentication Required | The client must first authenticate itself with the proxy. |
408 | Request Timeout | The server timed out waiting for the request. |
409 | Conflict | Indicates that the request could not be processed because of conflict in the request. |
410 | Gone | Indicates that the resource requested is no longer available and will not be available again. |
5xx status codes are Server Error status codes. These status codes indicate that the server failed to fulfill a valid request. Here are some of the 5xx status codes:
Status Code | Status | Description |
---|---|---|
500 | Internal Server Error | Server failed to fulfill a valid request due to an error on the server side. |
501 | Not Implemented | The server does not support the functionality required to fulfill the request. |
502 | Bad Gateway | The server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request. |
503 | Service Unavailable | The server is not ready to handle the request. |
504 | Gateway Timeout | The server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access. |
505 | HTTP Version Not Supported | The server does not support the HTTP protocol version used in the request. |
506 | Variant Also Negotiates | Transparent content negotiation for the request results in a circular reference. |
507 | Insufficient Storage | The server is unable to store the representation needed to complete the request. |
508 | Loop Detected | The server detected an infinite loop while processing the request. |
509 | Bandwidth Limit Exceeded | The server has exceeded the bandwidth specified by the server administrator. |
510 | Not Extended | Further extensions to the request are required for the server to fulfill it. |