开发者

RESTFul - Should i use a XMLSchema validation?

Im starting a Restful architecture (using JBoss Resteasy and Spring), i already did the basic setup (division of layers, configuration, content negotiation, URI design, etc). Its almost OK, to finish it, i still need clear some qu开发者_C百科estions, that are:

Should i use a XMLSchema validation for my services? When i need it? Its OK with the REST good practices ?

What about your opinion?

Thanks!


A simple way to think of XML Schemas (XSD) would be as strong typing for your XML definitions. The biggest advanage being that you could provider the XSD in place of WSDL so that people understand your message/payload definitions. The biggest downside being you have a much tighter platform so partial fragments could be much more difficult. If you are consuming your own stuff and not providing public APIs then XSD may or may not be useful.

As I do more with XML I have started to write the related XSD files so members of my team see the options in a known way. We can also use tooling to validate that inputs and outputs are formatted correctly and the XSD files even provider Intellisence for the related XML files within Visual Studio (I work primarily with .Net)

Long story short, it's up to you.


REST has no opinion on how you validate the content of passed representations.


You can use JSR 303 implementation: Hibernate Validator. Use @Valid annotation with @RequestBody and annotate your Model Object with any sort of validation you may want to do. To name a few : @NotNull, @NotBlank, @NotEmpty etc. etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜