在阅读了大量关于REST和SOAP之间的区别之后,我的印象是REST只是HTTP的另一种说法。有人能解释一下REST给HTTP添加了什么功能吗?

注意:我并不是在寻找REST和SOAP的比较。


当前回答

你不知道HTTP和REST之间的区别

因此REST体系结构和HTTP 1.1协议是相互独立的 其他,但HTTP 1.1协议被构建为理想的协议 遵循REST的原则和约束。一种方法是看 HTTP和REST之间的关系是,REST是设计,并且 HTTP 1.1就是这种设计的实现。

其他回答

REST api必须是超文本驱动的

Roy Fielding的博客中有一组方法来检查你正在构建的是HTTP API还是REST API:

API designers, please note the following rules before calling your creation a REST API: A REST API should not be dependent on any single communication protocol, though its successful mapping to a given protocol may be dependent on the availability of metadata, choice of methods, etc. In general, any protocol element that uses a URI for identification must allow any URI scheme to be used for the sake of that identification. [Failure here implies that identification is not separated from interaction.] A REST API should not contain any changes to the communication protocols aside from filling-out or fixing the details of underspecified bits of standard protocols, such as HTTP’s PATCH method or Link header field. Workarounds for broken implementations (such as those browsers stupid enough to believe that HTML defines HTTP’s method set) should be defined separately, or at least in appendices, with an expectation that the workaround will eventually be obsolete. [Failure here implies that the resource interfaces are object-specific, not generic.] A REST API should spend almost all of its descriptive effort in defining the media type(s) used for representing resources and driving application state, or in defining extended relation names and/or hypertext-enabled mark-up for existing standard media types. Any effort spent describing what methods to use on what URIs of interest should be entirely defined within the scope of the processing rules for a media type (and, in most cases, already defined by existing media types). [Failure here implies that out-of-band information is driving interaction instead of hypertext.] A REST API must not define fixed resource names or hierarchies (an obvious coupling of client and server). Servers must have the freedom to control their own namespace. Instead, allow servers to instruct clients on how to construct appropriate URIs, such as is done in HTML forms and URI templates, by defining those instructions within media types and link relations. [Failure here implies that clients are assuming a resource structure due to out-of band information, such as a domain-specific standard, which is the data-oriented equivalent to RPC’s functional coupling]. A REST API should never have “typed” resources that are significant to the client. Specification authors may use resource types for describing server implementation behind the interface, but those types must be irrelevant and invisible to the client. The only types that are significant to a client are the current representation’s media type and standardized relation names. [ditto] A REST API should be entered with no prior knowledge beyond the initial URI (bookmark) and set of standardized media types that are appropriate for the intended audience (i.e., expected to be understood by any client that might use the API). From that point on, all application state transitions must be driven by client selection of server-provided choices that are present in the received representations or implied by the user’s manipulation of those representations. The transitions may be determined (or limited by) the client’s knowledge of media types and resource communication mechanisms, both of which may be improved on-the-fly (e.g., code-on-demand). [Failure here implies that out-of-band information is driving interaction instead of hypertext.]

HTTP是一种在网络上传输消息的通信协议。 SOAP是一种用于交换基于xml的消息的协议,这些消息可以使用HTTP传输这些消息。 Rest是用于交换任何(XML或JSON)消息的协议,这些消息可以使用HTTP来传输。

HTTP是一种契约,一种通信协议,REST是一种概念,一种架构风格,可以使用HTTP、FTP或其他通信协议,但广泛与HTTP一起使用。

REST暗示了一系列关于服务器和客户端应该如何交互的约束。HTTP是一种具有特定机制的通信协议,用于服务器-客户端数据传输,它最常用于REST API,因为REST是受WWW (world wide web)的启发,在REST定义之前,WWW大量使用HTTP,因此使用HTTP更容易实现REST API风格。

REST中有三个主要的约束(但还有更多):

服务器和客户端之间的交互应该只通过超文本来描述。 服务器和客户端应该是松散耦合的,彼此之间不做任何假设。客户端应该只知道资源入口点。交互数据应该由服务器在响应中提供。 服务器不应该存储任何关于请求上下文的信息。请求必须是独立的和幂等的(意思是如果相同的请求无限次重复,得到的结果完全相同)

HTTP只是一种通信协议(一种工具),可以帮助实现这一点。

欲了解更多信息,请查看以下链接:

https://martinfowler.com/articles/richardsonMaturityModel.html http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven

REST强制使用可用的HTTP命令,因为它们应该被使用。

例如,我可以这样做:

GET
http://example.com?method=delete&item=xxx

但是休息时,我会使用“DELETE”请求方法,消除对“method”查询参数的需要

DELETE
http://example.com?item=xxx

REST不一定绑定到HTTP。基于rest的web服务只是遵循基于rest的体系结构的web服务。

What is Rest -
1- Client-server
2- Stateless
3- Cacheable
4- Layered system
5- Code on demand
6- Uniform interface