Wednesday, 26 July 2017

Http Status code















// Summary:
        //     Equivalent to HTTP status 100. System.Net.HttpStatusCode.Continue indicates
        //     that the client can continue with its request.
        Continue = 100,
        //
        // Summary:
        //     Equivalent to HTTP status 101. System.Net.HttpStatusCode.SwitchingProtocols
        //     indicates that the protocol version or protocol is being changed.
        SwitchingProtocols = 101,
   



Hi friends, If you go for a web developer Interview, then Interviewer most often ask about HTTP status codes, most common being: 200, 404, 500 etc. Please find below the list of all HTTP status codes with their explanation. Here we will describe the most important status codes available for use talking to HTTP 1.1 clients, along  with the standard message associated with each code. The
complete HTTP 1.1 specification is  given in RFC 2616. In general, you can access RFCs online by going to http://www.rfc-editor.org/  and following the links to the latest RFC archive sites, but since th is one came from the World Wide Web Consortium, you can just go to  http://www.w3.org/Protocols/ 

These codes fall into five general categories:
  • 100–199: Informational, indicating that the client should respond with some other action. 
  • 200–299 (Success): Signifies that the request was successful. 
  • 300–399 (Redirection): Used for files that have moved and usually include a Location  header indicating the new address. 
  • 400–499 (Client Error): Indicates an error by the client. 
  • 500–599 (Server Error): Signifies an error by the server.

Detailed Explanation:

  • 100 (Continue): If the server receives an Expect request header with a value of 100-continue, it means that the client is asking if it can send an attached document in a follow-up request. In such a case, the server should either respond with status 100 (SC_CONTINUE ) to tell the client to go ahead or use 417 (SC_EXPECTATION_FAILED ) to tell the browser it won’t accept the document. This status code is new in HTTP 1.1. 
  • 101 (Switching Proto)
  • 200 (OK): A value of 200 (SC_OK) means that everything is fine; the document follows for GET  and POST requests.
  • 201 Created
  • 202 (Accepted): A value of 202 (SC_ACCEPTED ) tells the client that the request is being acted upon but processing is not yet complete. 
  • 203 Non-Authoritative
  • 204 (No Content): A status code of 204 ( SC_NO_CONTENT ) stipulates that the browser should continue to display the previous document because no new document is avail-able. This behavior is useful if the user periodically reloads a page by pressing the Reload button and you can determine that the previous page is already up-to-date. 

  • 205 (Reset Content): A value of 205 (SC_RESET_CONTENT ) means that there is no new document but the browser should reset the document view. Thus, this status code is used to instruct browsers to clear form fields. It is new in HTTP 1.1. 

  • 206 Partial Content

  • 300 Multiple Choices

  • 301 (Moved Permanently): The 301 ( SC_MOVED_PERMANENTLY) status indicates that the requested document is elsewhere; the new URL for the document is given in the Location response header. Browsers should automatically follow the link to the new URL. Update your URL, this has moved for good.

  • 302 (Found): This value is similar to 301, except that in principle the URL given by the location  header should be interpreted  as a temporary replacement, not a permanent one. In practice, most browsers treat 301 and 302 identically.

    Status code 302 is useful because browsers automatically follow the reference to the new URL given in the Location  response header. Note that the browser reconnects to the new URL immediately; no intermediate output is displayed. This behavior distinguishes  redirects  from refreshes  where an inter-mediate page is temporarily displayed (see the next chapter for details on the Refresh header). if the original request was  GET . For details, see the discussion of the 307 status code. 

  • 303 (See Other): Its similar to 301 and 302, except that if the original request was POST, the new document (given in the  Location  header) should be retrieved with GET . See status code 307. This code is new in HTTP 1.1. 

  • 304 (Not Modified): When a client has a cached document, it can perform a conditional request by supplying an  If-Modified-Since header to signify that it wants the document only if it has been changed since the specified date. A value of 304 (SC_NOT_MODIFIED) means that the cached versio n is up-to-date and the cli-ent should use it. Otherwise, the server should return the  requested document with the normal (200) status code. 

  • 305 Use Proxy

  • 306 Unused

  • 307 (Temporary Redirect): The rules for how a browser should handle  a 307 status are identical to those for 302. The 307 value was added to HTTP 1.1 This is temporarly moved, don't update your bookmarks.

  • 400 (Bad Request): Server didn't understand the URL you gave it.
  • 401 (Unauthorized): A value of 401 (SC_UNAUTHORIZED) signifies that the client tried to access a password-protected page but that the request did not have proper identifying information in the  Authorization  header. 

  • 402 Payment Required =>Not used really

  • 403 (Forbidden): A status code of 403 ( SC_FORBIDDEN) means that the server refuses to supply the resource, regardless of authorization. This status is often the result of bad file or directory permissions on the server. 

  • 404 (Not Found): The infamous 404 ( SC_NOT_FOUND) status tells the client that no resource could be found at that address. This value is the standard “no such page” response.

  • 405 (Method Not Allowed): A 405 ( SC_METHOD_NOT_ALLOWED ) value signifies that the request method (GET ,  POST,  HEAD,  PUT ,  DELETE , etc.) was not allowed for this particular resource. This status code is new in HTTP 1.1. 

  • 406 Not Acceptable

  • 407 Proxy Authentication Required

  • 408 Request Timeout => Browser took too long to request something

  • 409 Conflict

  • 410 Gone

  • 411 Lengh Required

  • 412 Precondition Failed

  • 413 Reqeust Entity Too Large

  • 415 (Unsupported Media Type): A value of 415 (SC_UNSUPPORTED_MEDIA_TYPE) means that the request had an attached document of a type the se rver doesn’t know how to handle. This status code is new in HTTP 1.1. 

  • 416 Request Range Not Satisfactory

  • 417 (Expectation Failed): If the server receives an Expect request header with a value of 100-continue, it means that the client is aski ng if it can send an attached document in a follow-up request. In such a case, the server should either respond with this status (417) to tell the browser it won’t accept the document or use 100 ( SC_CONTINUE ) to tell the client to go ahead. This status code is new in HTTP 1.1. 

  • 500 (Internal Server Error): 500 (SC_INTERNAL_SERVER_ERROR) is the generic “server is confused” status code.  Something on the server didn't work right.

  • 501 (Not Implemented): The 501 ( SC_NOT_IMPLEMENTED ) status notifies the client that the server doesn’t support the functionality to fulfill the request. It is used, for example, when the client issues a command like PUT  that the server doesn’t support. 

  • 502 Bad Gateway

  • 503 (Service Unavailable): A status code of 503 ( SC_SERVICE_UNAVAILABLE) signifies that the server cannot respond because of maintenance or  overloading. For example, a servlet might return this header if some thread or database connection pool is cur-rently full. The server can supply a  Retry-After  header to tell the client when to try again. Too busy to respond to a client!

  • 504 Gateway Timeout
  • 505 (HTTP Version Not Supported): The 505 ( SC_HTTP_VERSION_NOT_SUPPORTED) code means that the server doesn’t support the version of HTTP named in the request line. This statutus code is new in http1.1



Here are some Tips:
DELETE
  • 200 (if your want send some additional data in the Response) or 204 (recommended).
  • 202 Operation deleted has not been committed yet.
  • If there's nothing to delete, use 204 or 404 (DELETE operation is idempotent, delete an already deleted item is operation successful, so you can return 204, but it's true that idempotent doesn't necessarily imply the same response)
Other errors:
  • 400 Bad Request (Malformed syntax or a bad query is strange but possible).
  • 401 Unauthorized Authentication failure
  • 403 Forbidden: Authorization failure or invalid Application ID.
  • 405 Not Allowed. Sure.
  • 409 Resource Conflict can be possible in complex systems.
  • And 501502 in case of errors.
PUT
If you're updating an element of a collection
  • 200/204 with the same reasons as DELETE above.
  • 202 if the operation has not been commited yet.
The referenced element doesn't exists:
  • PUT can be 201 (if you created the element because that is your behaviour)
  • 404 If you don't want to create elements via PUT.
  • 400 Bad Request (Malformed syntax or a bad query more common than in case of DELETE).
  • 401 Unauthorized
  • 403 Forbidden: Authentication failure or invalid Application ID.
  • 405 Not Allowed. Sure.
  • 409 Resource Conflict can be possible in complex systems, as in DELETE.
  • And 501502 in case of errors.



This page is created from HTTP status code information found at ietf.org and Wikipedia. Click on the category heading or the status code link to read more.



  

No comments:

Post a Comment