RESTful初探之一(What is REST)

英文tutorial guide
http://www.ibm.com/developerworks/java/tutorials/j-rest/
也是以下翻译的原文链接

RESTfull==REpresentation State Transfer没有好的中文翻译。

RESTfull是一组架构约束条件和原则。满足这些约束条件和原则的应用程序或设计就是 RESTful。

首先先得明白有状态和无状态。RPC框架中视图层是有状态的。

Web 应用程序最重要的 REST 原则是,客户端和服务器之间的交互在请求之间是无状态的。无状态意味着可随意分布式


REST 是一种依靠命名资源的低耦合web应用设计风格——in the form of Uniform Resource Locators(URLs),Uniform Resource Identifiers(URIs),and Uniform Resource Names,for instance——rather than messages.
以统一资源定位,统一资源标示,统一资源命名的形式实现,而不是动态的信息

REST leverages aspects of the HTTP protocol such as GET and POST request.
REST利用对HTTP协议如GET何Post请求的aspect

RESTfull真正veritable father在他的dissertation中说的:"
emphasizes scalability of component interactions, generality of interfaces,independent deployment of components,and intermediary components to reduce interaction latency,enforce security,and encapsulate legacy systems"
着重于组件交互的可扩展性,通用接口,独立部署组件和利用中间组件去减少交互延迟,强制安全性和封装遗留系统。

Everything on the Web(pages,images,and so on)is in essence a resource.REST's reliance on named resources rather than messages facilitates loose coupling in application design,because it limits the exposure of the underlying technology.For instance,the folowing URL exposes a resource without implying anything about the underlying technology:http://thediscoblog.com/2008/03/20/unambiguously-analyzing-metrics/
web(pages,images,and so on)本质上就是资源。REST 依赖命名的资源而不是报文,从而降低应用设计的耦合度。因为他限制底层技术的暴露。

this URL represents a resource —— an article called "Unambiguously analyzing metrics".A request for this resource leverages the HTTP GET command.Notice that
the URL is noun-based. A verb-based version(which might look something like http://thediscoblog.com/2008/03/20/getArticle?name=unambiguously-analyzing-metrics)would violate REST principles,because it embeds a message.in the form of getArticle.You could also imagine posting a new resouce(say, an article resource such as http://thediscoblog.com/2008/03/22/rest-is-good-for-you/)via HTTP's POST command.Although you can also imagine associated,verb-based APIs——such as createArticle?name=rest-is-good-for-you and deleteArticle?name=rest-is-good-for-you — such calls hijack the HTTP GET command and,for the most part,ignore the already available(and successful)HTTP infrastructure.In other words,they are not RESTful.
URL代表了一个资源,一篇名叫"Unambiguously analyzing metrics"的文章。注意这个请求是基于名词的,如果是基于动词的(如http://thediscoblog.com/2008/03/20/getArticle?name=unambiguously-analyzing-metrics),则会侵犯REST原则。因为他嵌入了一个报文,你可以根据这个动词联想其他文章,甚至其他的请求,如createArticle、deleteArticle。这样的请求劫持了get命令,更重要的是忽略了已经有效的HTTP基础。

The beauty of REST is that resources can be anything,and how they are represented can vary too.In the preceding example,the resource is an HTML file;accordingly,the format of the response would be HTML.But the resource could have easily been an XML document,serialized object,or JSON representation.It really doesn't matter.What matters is that a resource is named and that communication with it doesn't affect its state.Not affecting state is important because stateless interactions facilitate scalability.
REST的好处是资源可以使任何事物,并且如何表现也可以是多样化的。之前的例子,资源是HTML文件,因此response的格式可能是HTML,但是资源可以轻易地改为XML,序列化对象,或者JSON表现形式。这不是问题,问题是资源如何命名及访问它却不影响他的状态。

To quote LEonardo da Vinci,"simplicity is the ultimate sophistication"
引用那谁的话说:“简单才是最终极的复杂”

你可能感兴趣的:(Restful)