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




Asked on February 24, 2017
 While updating a resource, what HTTP method and HTTP status code should be used? I am creating a spring REST web service.





Replied on February 24, 2017

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






Write Answer











©2024 concretepage.com | Privacy Policy | Contact Us