Sunday, 19 June 2016

http - What exactly is RESTful programming?



What exactly is RESTful programming?





Answer



An architectural style called REST (Representational State Transfer) advocates that web applications should use HTTP as it was originally envisioned. Lookups should use GET requests. PUT, POST, and DELETE requests should be used for mutation, creation, and deletion respectively.



REST proponents tend to favor URLs, such as



http://myserver.com/catalog/item/1729


but the REST architecture does not require these "pretty URLs". A GET request with a parameter




http://myserver.com/catalog?item=1729


is every bit as RESTful.



Keep in mind that GET requests should never be used for updating information. For example, a GET request for adding an item to a cart



http://myserver.com/addToCart?cart=314159&item=1729



would not be appropriate. GET requests should be idempotent. That is, issuing a request twice should be no different from issuing it once. That's what makes the requests cacheable. An "add to cart" request is not idempotent—issuing it twice adds two copies of the item to the cart. A POST request is clearly appropriate in this context. Thus, even a RESTful web application needs its share of POST requests.



This is taken from the excellent book Core JavaServer faces book by David M. Geary.


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...