I'd like to avoid embedding HTML in XML returned from my JAX-RS web service, but still be able to return both XML and HTML in the response to a single GET.
Is there a开发者_开发百科 way to do this? Is it a bad idea?
Right now I am doing 2 separate GET's for different resources one XML one HTML - however since both resources are always retrieved together this seems wasteful and error-prone.
One way you could do it is using the rest principle of "Hypermedia as the engine of application state”, sometimes abbreviated as HATEOAS.
You can use a url as an attribute of your xml tag.
<htmlResponse ref='http://yourUrlForHtml.com/getHtml' />
So the client will be able to get both the xml and html return (if he wants). He can do 1 or 2 calls and it would not be wasteful.
精彩评论