API REST : produce JSON instead HTML by default

What product/components do you use and which version/fix level?

webMethods Integration Server 10.5

Are you using a free trial or a product with a customer license?

I have a license

What are trying to achieve? Please describe in detail.

I create an API REST using swagger first, and specify to produce only application/json.
But if in my Postman request I don’t specify the Accept, i’ll get an HTML return.

How can I configure IS to return JSON by default ?

There are many ways to accomplish this, but if using a “layered approach”, which means that in the context of “handling incoming requests and the corresponding responses”,

  • the IS is responsible for both receiving requests in any supported format and it should hand the received data in the IData format to the services, and
  • conversely, the IS is also responsible for “converting” the IData format to the requested format.

Hence, it is responsibility of the client to provide the format it accepts. Having this said, it is a matter of providing the HTTP Header "Accepts: application/json"in the requests. This will tell the IS to apply the proper “content handler” - in this case, JSON - to the whatever IS service output.

In another approach - this one assumes the service will always answer in JSON - you can hardcode the answer using the pub.flow:response2, pub.flow:setResponseCode, pub.flow:setResponseHeader / pub.flow:setResponseHeaders.

1 Like

I agree with your first answer, however, it’s seems SAG choice HTML as default format for the response if “Accept” is not filled in the HTTP Headers. This choice seems to be arbitrary to me, and, in my context, I want to deliver JSON format if “Accept” is not informed.
Maybe (and I hope) there is a configuration into the config.ini of the IS to change that.

You can change the default accept type via extended settings via the admin portal → Settings → Extended

Search on the property watt.net.default.accept

By default the value is not set, hence the default behaviour which is HTML

regards,
John.

It’s promise to be the way I’am looking for, thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.