I need to consume a REST service from Integration Server.
I currently do it is as follows:
Populate the content of the request in an IS document
Use pub.json:documentToJSONString to convert an IS document to a JSON representation
Use pub.client:http to make an HTTP request. The json string from the previous step is mapped to data/string. In order to have the right headers, I added content-type and Accept along with values to the headers input.
Is this the best way to do it in the current version (9.7)? Is it the only way?
Is this the best way to do it in the current version (9.7)? Is it the only way?<<<
It is indeed the way to do it if you are communicating with a non-IS server.
If youāre talking to another IS, you can use the (new in 9.7) com.wm.app.b2b.client.JSONClient. This class is very similar to com.wm.app.b2b.client.Context, which you may be familiar with, but it transmits JSON payloads rather than binary-encoded or xml-encoded IData.
I got a requirement like, My client will send JSON data(Inbound JSON data) and we need to validate and send response if it is valid data if it is not valid we need to send an error email.
Could you please let me know,
How to validate JSON data since we don not have built-in service to validate the JSON data (like we have built in services for flat and xml files)
Could you please let me know the services to send response (Is it pub.flow.setResponse or pub.client.http )
Create a Document type on IS against which you want to validate the JSON.
Convert the inbound JSON to document using pub.json:jsonStringToDocument or pub.json:jsonStreamToDocument what ever is relevant.
Use pub.schema:validate and map your output document from Step-2 to āobjectā and set āconformsToā as the document type you created in Step-1
Regarding response, if your source is calling via some javascript and set the HTTP header āAcceptā or āContent-typeā to āapplication/jsonā then you need not do anything from your side on IS. The response will go just fine. But it is better to use pub.flow:setResponseHeader and set āfieldNameā as ācontent-typeā, āfieldValueā as āapplication/jsonNā. Whatever is the output of your flow service will now go as JSON to the source.