本文内容主要总结摘录自MSDN,和园子里reni和万法自然关于REST的文章。
MSDN:
Besides SOAP there is an alternative for the realization of Web services. In his dissertation Thomas Roy Fielding describes an architectural style he calles REpresentational State Transfer architecture , briefly REST. REST is based on principles, which are used in the largest distributed application - the World Wide Web. Without intention there are many search engines, shops or booking systems that are already available as REST based Web services. The REpresentational State Transfer architecture is an architecture that describes how the Web should work. REST is neither a product nor a standard.
REST defines an architectural style based on a set of constraints for building things the “Web” way. REST is not tied to any particular technology or platform – it’s simply a way to design things to work like the Web. People often refer to services that follow this philosophy as “RESTful services.”
The GET method allows you to retrieve a resource representation, while PUT allows you to create or update a resource with the supplied representation, and DELETE allows youto delete a resource. In short, GET, PUT, and DELETE provide basic CRUD operations (create, retrieve, update, and delete) for the Web. HEAD and OPTIONS, on the other hand, provide the ability to retrieve resource metadata, allowing you to discover out how to interact with resources at run time.
Although HTTP fully supports CRUD, HTML 4 only supports issuing GET and POST requests through its various elements. This limitation has held Web applications back frommaking full use of HTTP, and to work around it, most applications overload POST to take care of everything but resource retrieval. HTML 5, which is currently under development,plans to fix this by adding new support for PUT and DELETE.
总体描述:
表述性状态转移(Representational State Transfer,REST),不是一种标准,而是一种软件架构风格。基于REST的服务与基于SOAP的服务相比,性能、效率和易用性上都更高,而SOAP协议非常的复杂和不透明。REST受到越来越多的Web服务供应商欢迎。目前大部分供应商,如yahoo、google、Amazon等都提供REST风格的服务。
REST的主要原则是:
1.网络上的所有事物都可被抽象为资源;
2.每个资源都有一个唯一的资源标识符URI;
3.使用标准方法操作资源;
4.所有的操作都是无状态的;
5.通过缓存来提高性能。
REST是基于Http协议的,任何对资源的操作行为都是通过Http协议来实现。Http把对一个资源的操作限制在4个方法以内:GET、POST、PUT和DELETE,这正是对资源CRUD操作的实现。REST的资源表述形式可以是XML、HTML、JSON,或者其他任意的形式,这取决于服务提供商和消费服务的用户。
但是REST不是万能的。操作无状态也会带来巨大的安全问题,如何授权和验证用户?如果要求每次请求都包含完整的身份和验证信息,又如何避免信息泄漏?复杂的功能挑战架构的易用性,这就需要在性能与功能间权衡,究竟该用REST还是SOAP。
虽然REST包含无状态性(statelessness)的观念,但这并不是说暴露功能的应用不能有状态。事实上,在大部分情况下这会导致整个做法没有任何用处。REST要求状态要么被放入资源状态中,要么保存在客户端上。或者换句话说,服务器端不能保持除了单次请求之外的,任何与其通信的客户端的通信状态。这样做的最直接的理由就是可伸缩性。