简体   繁体   English

RESTful Web服务是否支持合同优先和合同后两种方法?

[英]Do RESTful web services support both contract-first and contract-last approaches?

RESTful Web服务(例如,在JAX-RS实现中)是否支持合同优先(自上而下)方法和合同最后(自下而上)方法?

Do RESTful web services support both contract-first and contract-last approaches? RESTful Web服务是否支持合同优先和合同后两种方法?

It depends on what tools/frameworks you use. 这取决于您使用什么工具/框架。

What you are talking about applies to a SOAP web service and its accompanying WSDL. 您所讨论的内容适用于SOAP Web服务及其随附的WSDL。

A WSDL describes what a web service expects as input and what should a client expect as output. WSDL描述了Web服务期望作为输入的内容以及客户端期望作为输出的内容。 It defines the contract to be followed in order for both parties to communicate with each other. 它定义了要使双方相互通信要遵循的合同。 You can obtain the WSDL by doing contract-first or contract-last and you can later use this WSDL to generate code for a client stub or a service skeleton. 您可以通过首先签约或最后签约来获取WSDL,然后可以使用此WSDL为客户端存根或服务框架生成代码。

But doing REST isn't the same as doing SOAP. 但是,进行REST与进行SOAP并不相同。 Processes that worked for SOAP (a protocol) can't necessarily be applied to REST (an architectural style) just because we are familiar with them. 仅仅因为我们对SOAP(一种协议)有用的过程并不一定会应用于REST(一种体系结构样式)。

Unlike SOAP that exposes methods and method signatures, REST exposes resources. 与公开方法和方法签名的SOAP不同,REST公开资源。 An understanding of the media types used in the exchange of those resources is all a REST client needs in order to communicate with a REST web service. 为了与REST Web服务进行通信,REST客户端仅需要了解这些资源交换中使用的媒体类型。 There is no need for a separate document to describe the resources. 不需要单独的文档来描述资源。

Because of the HATEOAS principle, REST clients are more dynamic and can adapt to other services that communicate using the same media types. 由于具有HATEOAS原理,REST客户端更加动态,可以适应使用相同媒体类型进行通信的其他服务。 Exposing static service description documents would be limiting for a REST service. 公开静态服务描述文档将限制REST服务。

Having said that, there are REST tools that do expose a description document, for example Jersey who exposes a WADL (contract-last). 话虽如此,有些REST工具确实公开了描述文档,例如, Jersey公开了WADL (最后合同)。 I'm sure you can use the published WADL to build client stubs and I don't see a reason why you couldn't write the WADL by hand (contract-first) and use it to generate stubs and skeletons. 我确定您可以使用已发布的WADL来构建客户端存根,并且我看不出您不能手动(合同优先)编写WADL并使用它来生成存根和框架的原因。 But as I said, that might not be the best solution for REST. 但是正如我所说,这可能不是REST的最佳解决方案。

Here are some posts you might want to read to form an opinion if contract-last or contract-first approaches make sense in REST: 如果在REST中采用后契约或先契约的方法,则可能需要阅读以下几篇文章以形成意见:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM