What exactly is RESTful programming?

前端 未结 30 3263
Happy的楠姐
Happy的楠姐 2020-11-21 06:02

What exactly is RESTful programming?

30条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 06:46

    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.

提交回复
热议问题