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

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

问题描述

RESTful 编程究竟是什么?

What exactly is RESTful programming?

推荐答案

一种架构风格,称为 REST(具象状态传输) 主张 Web 应用程序应该像 最初设想的那样使用 HTTP.查找应使用 GET 请求.PUTPOSTDELETE请求分别用于变异创建删除.

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 请求应该是幂等.也就是说,两次发出请求应该与发出一次请求没有什么不同.这就是使请求可缓存的原因.加入购物车"request 不是幂等的——发出两次会将该项目的两个副本添加到购物车中.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.

这摘自 David M. Geary 所著的优秀书籍 Core JavaServer faces.

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

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

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