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 Answer 1

1

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.

1
  • 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
    Jan 29, 2010 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.