Example for how to do a switch between xml and json ?

6 views
Skip to first unread message

Dmitry G

unread,
Oct 27, 2011, 4:39:19 PM10/27/11
to Bowler Users
Hi,

Could someone post a quickie snippet illustrating how to do the
following in bowler:

An example of how to process a request which contains the desired
serialization choice embedded in it, e.g.: /myservice/getitems.{xml |
json} as well as /myservice/additem.{xml | json}

Thanks so much,
- Dmitry

Wille Faler

unread,
Oct 27, 2011, 5:27:12 PM10/27/11
to bowler...@googlegroups.com
There is a post I wrote some time ago that explains how the request and response pipelines work (with some UML pictures): http://blog.recursivity.com/post/5433171352/how-bowler-does-rendering-maps-requests-to-objects

..the default Bowler RenderStrategy uses the http "Accept" header provided by the client to decide whether to use HTML, JSON or something else to render back (for instance if you pass in "Accept: application/json" it will choose the JsonViewRenderer.

What you need to do to add XML rendering is add your own "XmlViewRenderer" (we don't provide one out of the box) and map it to requests with the Accept header of "application/xml".

If you want to do it by path, you would need to provide your own RenderStrategy instead of the default one (Accept header mapping is really the recommended "http way" of doing it, however the Rails community have perpetuated some slightly worse practices).

Dmitry G

unread,
Oct 31, 2011, 10:30:42 AM10/31/11
to Bowler Users
Thank you for the recommendations, Wille!
Reply all
Reply to author
Forward
0 new messages