RESTful编程究竟是什么? [英] What exactly is RESTful programming?

查看:108
本文介绍了RESTful编程究竟是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

RESTful编程究竟是什么?

What exactly is RESTful programming?

推荐答案

架构风格名为 REST(代表性国家转移) 提倡该网络应用程序应使用HTTP,因为最初设想。查找应使用 GET 要求。 PUT POST DELETE 请求应分别用于变异,创建和删除

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支持者倾向于支持URL,例如

REST proponents tend to favor URLs, such as

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

但REST架构不需要这些漂亮的URL 。带参数的GET请求

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

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

每一位都是RESTful。

is every bit as RESTful.

请记住,GET请求应该是永远不会用于更新信息。例如,将商品添加到购物车的GET请求

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

不合适。 GET请求应为幂等。也就是说,两次发出请求应该与发出一次请求没有什么不同。这就是使请求可缓存的原因。 添加到购物车请求不是幂等的 - 发布它两次将该项目的两个副本添加到购物车。在这种情况下,POST请求显然是合适的。因此,即使 RESTful Web应用程序也需要其POST请求的份额。

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.

这取自优秀的书籍 Core JavaServer faces David M. Geary的书。

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

这篇关于RESTful编程究竟是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆