JSON RESTful Web服务是否应使用数据协定 [英] Should JSON RESTful web services use data contract

查看:84
本文介绍了JSON RESTful Web服务是否应使用数据协定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这实际上是一个设计问题. 我想知道带有JSON负载的Spring3.0 REST Web服务是否提供类似于遵循契约优先设计的传统Web服务的某种数据契约. 我知道JSON具有类似于XSD的架构,但是在春天它适合哪里呢? 背景: 我考虑将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服务的合同"是在WSDL文件(包括XSD)中定义的.使用RESTful服务,这些文件称为 WADL .而且spring-mvc不支持生成WADL. (JAX-RS实现有).

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).

但是,即使这样做,RESTful服务也被认为是动态的",不需要像这样固定它们.例如,看看Facebook和twitter的REST API.他们不提供WADL或JSON模式.他们提供了一些有关其服务的自由格式的文档.这样就足够了.

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.

这篇关于JSON RESTful Web服务是否应使用数据协定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆