restv2 web output / how to

Hello,

I’ve created a rest v2 resource that points to my service and has access only to the GET method.

When I call the rest service in the browser ( http://ishost:5555/restv2/myservice/ ) i get the details that the service should output, but is using the IS html in the background. ( imagine that you go into IS > packages > package service > run service with / without inputs… is the same style of output )

What do I have to do to make the output xml / json ?

I can’t find anywhere in the documentation how to control this, please let me know if this should be posted in a different section.

Capture.PNG

I think you have to specify the “Accept” header in your HTTP request to indicate which response format you wish. Since, if you call the service via browser, the desired response type is HTML, the IS generates it. Try curl to issue the requests.

1 Like

Maybe you can give a try using pub.flow:setResponse2

1 Like

That’s also possible, and I’ve used this myself. The drawback of this solution is that the format of the response is fixed and can’t be set by the caller. This can be improved by introducing a service input parameter that would tell in which format the response should be delivered (this value would be used in the call to setResponse2). But adding this parameter would spoil the service interface. Hence I prefer, if calling the service via HTTP, to tell the desired format via HTTP header.

1 Like

Hello,

Thank you both for the explanation and guidelines.
Using curl I can see the output as json.
All I had to do is to use the “Content-type” and the “Accept” in the header request.

I’m adding a url to an example if anyone else will need more details in the future: