Pages

Important HTTP codes for Rest web services

As all of us know that when we send a request to HTTP server, server returns the response of the request and also send a  status code. these status codes have special meaning for the client so a as software engineer  we must have knowledge about these codes. HTTP code have three digits like 200.

As we know that web services like consumes by program not directly by user, so web services should return HTTP status code very carefully, because based on these case consumer of web service will take action.

When a resource is created, the response code should be 201 (“Created”) and the Location header should point the way to the resource’s location.

When a resource is modified, the response code should be 200 (“OK”). If the resource state changes in a way that changes the URI to the resource (for instance, a user account is renamed), the response code is 301 (“Moved Permanently”) and the Location header should provide the new URI.

When an object is deleted, the response code should be 200 (“OK”).

We can use the 401 response code (“Unau-thorized”) any time the client tries to do something (edit a user’s account) without providing the proper Authorization header.

a client might try to rename a user account to a name that already exists. The 409 (“Conflict”) response code is appropriate here.

we will use 400 when a user tries to create or modify a resource, but doesn’t provide a valid representation.


Here I am listing some of the Important status code that everyone should know.
I took this article from www.w3.org. This site explain all the available status code very nicely.

There are 5 categories of HTTP code.

Category 1 : Start with digit "1"
1xx: Informational - Request received, continuing process

Category 2 : Start with digit "2"
2xx: Success - The action was successfully received, understood, and accepted

Category 3 : Start with digit "3"
3xx: Redirection - Further action must be taken in order to complete the request

Category 4 : Start with digit "4"
4xx: Client Error - The request contains bad syntax or cannot be fulfilled

Category 5 : Start with digit "5"
5xx: Server Error - The server failed to fulfill an apparently valid request





Here we are listing some important status code --

200     OK - client's request was successfully received, understood, and accepted.

201     Created - The request has been fulfilled and resulted in a new resource being created

202     Accepted- The request has been accepted for processing, but the processing has not been completed



301     Moved Permanently - The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs

302     Found - The requested resource resides temporarily under a different URI.

307     Temporary Redirect - The requested resource resides temporarily under a different URI

400     Bad Request - could not be understood by the server due to malformed syntax

401     Unauthorized

404     Not Found - The server has not found anything matching the Request-URI

405     Method Not Allowed -  The method specified in the Request-Line is not allowed for the resource identified by the Request-URI

406     Not Acceptable

500     Internal Server Error- The server encountered an unexpected condition which prevented it from fulfilling the request


503     Service Unavailable - The server is currently unable to handle the request due to a temporary overloading or maintenance


REST Architecture

No comments:

Post a Comment