One Star

How to allow user to select JSON or XML response from tRESTRequest

Can anyone explain to me how to get the tRESTRequest component to allow the user to specify whether to return either JSON or XML?  I can get my service to return JSON by setting "Produces=JSON" and it returns XML by setting "Produces=XML".  However, when I set "Produces=XML or JSON", I am only able to get XML response.
I should add that I am accessing this from my browser (Chrome).  So for example, I am going to http://localhost:8088/customers and I would like to know whether it is possible to add something to the end of that URL which would tell the service whether to return XML or JSON.  Is it possible to do this through the URL?
Thanks.
2 REPLIES
Community Manager

Re: How to allow user to select JSON or XML response from tRESTRequest

Hi 
If you use tRestClient to call the webservice  and select Accept type as 'JSON' on tRestClient, it will return json response.
ID: 1
Response-Code: 200
Encoding: ISO-8859-1
Content-Type: application/json
Headers: {content-type=, Date=, Server=, transfer-encoding=}
Payload: {"root":{"person":}}


Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: How to allow user to select JSON or XML response from tRESTRequest

Shong,
I tried your suggestion but it does not appear to be working as expected.  I selected "JSON" form the "Accept Type" dropdown and I still get XML.  I also set the header of "Accept" and "application/json" and I still get XML.  Next, I discovered that if you set the value of "Accept Type" to "Any" and specify a header of "Accept" = "application/json", then you get JSON, but you can't get JSON if you select "JSON" from the dropdown.
I have attached screenshots showing the following:
1. Select "Accept Type=JSON" and set header of "Accept = application/json".  Output is XML.
2. Change "Accept Type=Any" and leave the same header.  Output is JSON.
Am I doing something wrong that is causing me to be unable to get JSON output when I select JSON from the dropdown?