How to set API response default to JSON (instead of XML)

2,636 views
Skip to first unread message

Arif

unread,
Dec 4, 2014, 5:41:04 AM12/4/14
to opentrippl...@googlegroups.com
Hi,

OTP REST API returns response in XML format(default). We can change this to JSON by sending a request header "Accept: application/json".
As I am planning to use only JSON in my app. I wonder if there is an easy way to change default behavior to JSON by changing configuration or adding/removing small piece of code etc.

Thanks for help.

Arif

Marko Burjek

unread,
Dec 4, 2014, 5:55:37 AM12/4/14
to opentripplanner-users
This is commit that I think changed default API output from XML to JSON: https://github.com/opentripplanner/OpenTripPlanner/commit/f69a2b863cd743b35e6de9f4c342e7242

It is already in latest stable version 0.12.1 so it should already work.(JSON should be preffered) If you work on 0.11 file names are little different.
If this doesn't work try removing XML format in API calls.

--
You received this message because you are subscribed to the Google Groups "OpenTripPlanner Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to opentripplanner-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Arif

unread,
Dec 4, 2014, 6:36:05 AM12/4/14
to opentrippl...@googlegroups.com
Hi,
thank you Marko for your feedback.

I have switched to master branch (I have tried switching to opentripplanner-0.12.1 tag as well) but still default response type is XML


Arif

Arif

unread,
Dec 4, 2014, 7:24:37 AM12/4/14
to opentrippl...@googlegroups.com
Sorry, it was my mistake. I was trying google chrome for get requests and I found out that chorme itself was appending request header "application/xml". I tried REST client, it (master branch) is working  as expected. Thanks.

Arif

Laurent Gregoire

unread,
Dec 4, 2014, 8:15:34 AM12/4/14
to opentrippl...@googlegroups.com
Hi Arif,

On 04/12/14 13:24, Arif wrote:
> Sorry, it was my mistake. I was trying google chrome for get requests and I
> found out that chorme itself was appending request header "application/xml".
> I tried REST client, it (master branch) is working as expected. Thanks.

I think it's always better anyway to specify the expected format in the
client request. Otherwise you risk breaking your client in case the JSON
vs XML priority change on the server.

HTH,

--Laurent


Reply all
Reply to author
Forward
0 new messages