HTTP Method and HTTP Status Code to Update a Resource in REST Web Service


To update an existing resource PUT HTTP method should be
used. Request will hit with a resource id. To return the HTTP status code, it depends
on scenario.
1. If resource is not available, a new resource can be created
and HTTP status code 201 (Created) should be returned.
2. If resource is already there and successfully modified
then either 200 (OK) or 204 (No content) HTTP status code should be returned.
3. If the resource cannot be created or modified then an appropriate
error HTTP status code should be returned.
4. If the request cannot
be handled then we should not ignore the response and HTTP status code 501 (Not
Implemented) must be returned.
5. If the scenario is
that server desires that the request should be applied to a different URI then HTTP
status code 301 (Moved Permanently) must be returned. Now the user agent will
decide whether to redirect or not redirect the request.
Find the link
https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html