views:

39

answers:

1

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.

+1  A: 

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.

Diego Dias
This is pretty close to what I am doing at the moment. Though the client already knows the URI for both resources in advance. Thanks for the HATEOS tip, I had never heard of it.
sylvanaar