Reputation: 21257
In JAX-RS is there any way to define response type using query parameters instead of Accept header (e.g. /api/foo?format=json
)?
Upvotes: 1
Views: 628
Reputation: 596
In that case you need to enable one switch in web.xml like below
<context-param>
<param-name>resteasy.media.type.param.mapping</param-name>
<param-value>format</param-value>
</context-param>
/api/foo?format=json
Upvotes: 0
Reputation: 6660
There are three ways to do content negotiation in JAX-RS: based on URL, based on Accept header and based on request parameter. Please check out link Content Negotiation Based on Request Parameter. It contains sample code how to do content negotiation on request parameter. The link is for Apache Wink project, but the code should work in Jersey implementation.
Upvotes: 4
Reputation: 128799
I'm not aware of a built-in way to do it based on a query parameter, but the UriConnegFilter supports the suggested method of using a URI suffix, like /api/foo.json
. Maybe you could conform to that convention? If not, the UriConnegFilter would be a good starting place for building your own support for using query parameters.
Upvotes: 1