ASP.NET Core MVC - What are HTTP Status Codes?

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.

404

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.

Error Types

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.

Ex:

  1. 100 Continue - This interim response indicates that the client should continue the request or ignore the response if the request is already finished.
  2. 101 Switching protocols - This code is sent in response to an Upgrade request 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.

Ex:

  1. 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.
    • PUT or 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.
  2. 202 Accepted - The request is accepted for processing, but the processing is not complete.
  3. 201 Created - The request is complete, and a new resource is created .
  4. 203 Non-authoritative Information - The information in the entity header is from a local or third-party copy, not from the original server.
  5. 204 No Content - A status code and a header are given in the response, but there is no entity-body in the reply.
  6. 205 Reset Content - The browser should clear the form used for this transaction for additional input.
  7. 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.

Ex:

  1. 300 Multiple Choices - A link list. The user can select a link and go to that location. Maximum five addresses .
  2. 301 Moved Permanently - The requested page has moved to a new url .
  3. 302 Found - The requested page has moved temporarily to a new url .
  4. 303 See Other - The requested page can be found under a different url .
  5. 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.
  6. 305 Use Proxy - The requested URL must be accessed through the proxy mentioned in the Location header.
  7. 306 Unused - This code was used in a previous version. It is no longer used, but the code is reserved.
  8. 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.

Ex:

  1. 400 Bad Request - The server did not understand the request.
  2. 401 Unauthorised - The requested page needs a username and a password.
  3. 402 Payment Required - You can not use this code yet.
  4. 403 Forbidden - Access is forbidden to the requested page.
  5. 404 Not Found - The server can not find the requested page.
  6. 405 Method Not Allowed - The method specified in the request is not allowed.
  7. 406 Not Acceptable - The server can only generate a response that is not accepted by the client.
  8. 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.

Ex:

  1. 500 Internal Server Error - The request was not completed. The server met an unexpected condition.
  2. 501 Not Implemented - The request was not completed. The server did not support the functionality required.
  3. 502 Bad Gateway - The request was not completed. The server received an invalid response from the upstream server.
  4. 503 Service Unavailable - The request was not completed. The server is temporarily overloading or down.
  5. 504 Gateway Timeout - The gateway has timed out.
  6. 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.