JSON RESTful Web 服务是否应该使用数据契约
这其实是一个设计问题。 我想知道携带 JSON 有效负载的 Spring3.0 REST Web 服务是否提供某种类似于遵循契约优先设计的传统 Web 服务的数据契约。 我知道 JSON 的架构与 XSD 类似,但它适合 spring 的什么地方? 背景: 我考虑使用 json 作为客户端服务器架构项目的有效负载,其中客户端是基于 .NET 的应用程序,并且数据契约应该提供一种处理客户端的多个版本的方法。客户端应该能够将数据结构发布到服务器。 或者也许我应该采用无模式方法并使用类似于 XmlAnyElement 的“简单数据绑定”?
This is actually a design question.
I'm wondering if Spring3.0 REST web services that carries JSON payload provide some kind of data contract similar to traditional web services which follows contract-first design.
I know that JSON has schema similar to XSD but where does it fits in spring ?
Background:
I consider using json as the payload of a client server architecture project where the client is .NET based application and data contract should provide a way to handle multiple versions of the client. The client should be able to post data structures to the server.
Or maybe I should take a schema-less approach and use "Simple Data Binding" which is similar to XmlAnyElement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与“常规”Web 服务的“合同”在 WSDL 文件(包括 XSD)中定义。对于 RESTful 服务,这些文件称为 WADL。并且 spring-mvc 不支持生成 WADL。 (JAX-RS 实现有)。
但即使这样做,RESTful 服务也被认为更加“动态”,并且不需要像那样进行修复。例如,看一下 Facebook 和 Twitter 的 REST API。他们不提供 WADL 或 JSON 架构。他们提供一些自由格式的服务文档。这应该足够了。
The "contract" with "regular" web-services is defined in WSDL files (which include XSDs). With RESTful services these files are called WADL. And spring-mvc does not have support for generating WADLs. (JAX-RS implementations have).
But even if if did, RESTful services are considered more "dynamic" and they don't need to be fixed like that. For example take a look at Facebook's and twitter's REST APIs. They don't provide WADLs or JSON schemas. They provide some free-form documentation of their services. That should be sufficient.
如果应该允许客户端模拟服务以对客户端进行单元测试(实际上他们应该这样做),那么服务应该提供合同。自由形式的文档并不是可靠的测试基础,因为它为误解留下了空间,而合同则不然。
If clients should be enabled to mock the services for unit testing the client (and actually they should), the services should provide a contract. Free form documentation is not a reliable base for testing, because it leaves space for misunderstanding, while contracts don't.
JSON Schema 和 Hyper-Schema 是用于指定内容和内容协商的 JSON Schema 格式。
我一直在使用 JSON Hyper Schema 开发 HATEOAS(超媒体作为应用程序状态引擎)API。
您可以访问下面的 URL,浏览、注册、登录并执行一些操作。
在这里查看一下:
http://direct.psprt.com:8081/
到目前为止,我还开源了我的实际 API 代码:
http://bpanahij.github.io/passportedu_schema/
欢迎查看、借用和使用评论。
另外,请查看 Javascript JSON-Hyper-Schema 客户端。它通过使用 OPTIONS 方法解析给定资源端点提供的架构,使用 Angular 动态构建 HTML 客户端应用程序。
https://github.com/bpanahij/passportedu_schema/tree/master/client
JSON Schema and Hyper-Schema are JSON Schema formats for specifying content and content negotiation.
I have been working on a HATEOAS (Hypermedia as the engine of application state) API, using JSON Hyper Schema.
You can go to the URL below, browse around, register, login and do some actions.
Check it out, here:
http://direct.psprt.com:8081/
I also open sourced my actual API code thus far:
http://bpanahij.github.io/passportedu_schema/
Feel free to take a look, borrow, and comment.
Also, check out the Javascript JSON-Hyper-Schema client. It dynamically builds an HTML client app using Angular, by parsing the Schema provided at a given resources endpoint with the OPTIONS method.
https://github.com/bpanahij/passportedu_schema/tree/master/client