ASP.NET Core MVC — What are HTTP Status Codes?
Any RESTful Web API relies on request and response. Every status code has a specific significance, and we must ensure that we are sending a proper answer with a valid status code during development.
Why HTTP Status Codes ?
HTTP response status codes represent whether or not a specific HTTP request were successfully completed. These responses are divided into the following 5 categories.
The Status-Code element in a server response is a three-digit integer where the first digit indicates the response type and the final two digits have no classifications role.
1. Informational Responses
These codes are informative, they are telling like the server has received a request and is continuing to process.
- 100 Continue — This interim response indicates that the client should continue the request or ignore the response if the request is already finished.
- 101 Switching protocols — This code is sent in response to an
Upgraderequest header from the client and indicates the protocol the server is switching to.
2. Succesful Responses
This means the request has been successful and the browser has received the expected information data.
- 200 OK — The request is OK. The request succeeded. The result meaning of “success” depends on the HTTP method:
GET: The resource has been fetched and transmitted in the message body.
HEAD: The representation headers are included in the response without any message body.
POST: The resource describing the result of the action is transmitted in the message body.
TRACE: The message body contains the request message as received by the server.
- 202 Accepted — The request is accepted for processing, but the processing is not complete.
- 201 Created — The request is complete, and a new resource is created .
- 203 Non-authoritative Information — The information in the entity header is from a local or third-party copy, not from the original server.
- 204 No Content — A status code and a header are given in the response, but there is no entity-body in the reply.
- 205 Reset Content — The browser should clear the form used for this transaction for additional input.
- 206 Partial Content — The server is returning partial data of the size requested. Used in response to a request specifying a Range header. The server must specify the range included in the response with the Content-Range header.
3. Redirection Responses
This code says that we have been redirected and completion of the request need further actions.
- 300 Multiple Choices — A link list. The user can select a link and go to that location. Maximum five addresses .
- 301 Moved Permanently — The requested page has moved to a new url .
- 302 Found — The requested page has moved temporarily to a new url .
- 303 See Other — The requested page can be found under a different url .
- 304 Not Modified — This is the response code to an If-Modified-Since or If-None-Match header, where the URL has not been modified since the specified date.
- 305 Use Proxy — The requested URL must be accessed through the proxy mentioned in the Location header.
- 306 Unused — This code was used in a previous version. It is no longer used, but the code is reserved.
- 307 Temporary Redirect — The requested page has moved temporarily to a new url.
4. Client Error Responses
This indicates the client errors such as some pages cannot be reached, unavailable etc.
- 400 Bad Request — The server did not understand the request.
- 401 Unauthorised — The requested page needs a username and a password.
- 402 Payment Required — You can not use this code yet.
- 403 Forbidden — Access is forbidden to the requested page.
- 404 Not Found — The server can not find the requested page.
- 405 Method Not Allowed — The method specified in the request is not allowed.
- 406 Not Acceptable — The server can only generate a response that is not accepted by the client.
- 407 Proxy Authentication Required — You must authenticate with a proxy server before this request can be served.
5. Server Error
These are the code that tells request is valid but the server could not complete the request.
- 500 Internal Server Error — The request was not completed. The server met an unexpected condition.
- 501 Not Implemented — The request was not completed. The server did not support the functionality required.
- 502 Bad Gateway — The request was not completed. The server received an invalid response from the upstream server.
- 503 Service Unavailable — The request was not completed. The server is temporarily overloading or down.
- 504 Gateway Timeout — The gateway has timed out.
- 505 HTTP Version Not Supported — The server does not support the “http protocol” version.
You can learn more information via Microsoft’s Official Documentation here.