开发者

How do you return multipart content from a JAX-RS web service?

开发者 https://www.devze.com 2022-12-18 14:16 出处:网络
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.

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.

0

精彩评论

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