Am 24.03.11 21:11, schrieb Mike Hugo:
> Hello,
> Is it possible to specify the response format by using a format
> parameter? For instance,
>
> http://myurl.com/api/serviceName?format=json
> OR
> http://myurl.com/api/serviceName?format=xml
>
In general, yes: you have access to the request parameter in resource
classes via the JAX-RS @Context. This allows you to create a response
(using the JAX-RS ResponseBuilder) with the response media type defined
in the URL. This media type is then used by the JAX-RS runtime to either
choose a default message body writer or a custom message body writer.
For Grails domain objects: not supported out of the box. Here, you'll
need to set the response media type in the resource methods using the
ResponseBuilder.type() method, as described above. Shouldn't be a big
deal to change resources classes (generated via 'grails
generate-resources') to use the format parameter instead - but I didn't
try that.
Does that help?
I'm curious: what speaks against using the Accept request header for
content negotiation?. I'm thinking about to support that out-of-the box
for domain objects if there's a good reason for not using the Accept header.
> ?
>
> Thanks for all the work on the plugin, we're starting to use it to
> expose some web services and things are going very nicely.
You're most welcome.
Cheers,
Martin
> Mike
--
Martin Krasser
blog: http://krasserm.blogspot.com
code: http://github.com/krasserm
twitter: http://twitter.com/mrt1nz
Thanks for sharing your ideas. Setting init parameters for Jersey is
definitely something useful. I created a ticket for it:
http://code.google.com/p/grails-jaxrs/issues/detail?id=38. I'm thinking
about a map of init parameters that can be defined in Config.groovy. We
could even use the same mechanism to set init parameters for the
RestletServlet as well.
Cheers,
Martin
Am 01.04.11 04:08, schrieb ebakke:
I just pushed support for
http://code.google.com/p/grails-jaxrs/wiki/AdvancedFeatures?ts=1301645620&updated=AdvancedFeatures#Init_parameters
to master
(https://github.com/krasserm/grails-jaxrs/commit/21ce038845772c55580fd1234f304342993fc553).
Please let me know if this fits your needs.
For testing, you'll need to checkout the sources and build the plugin
yourself as described in
http://code.google.com/p/grails-jaxrs/wiki/InstallationInstructions.
Cheers,
Martin
Am 01.04.11 08:15, schrieb Martin Krasser:
Glad that I could help.
Cheers,
Martin