Introduction:
This article explains about creating APIs on webMethods.io Integration that support both JSON and XML Content Types.
Creating APIs:
REST APIs can be created on webMethods.io Integration using REST API Builder. REST API Builder offers the developers to create APIs using either workflows/integrations. By default, all the APIs created support JSON Content Types. Developers are also allowed create APIs that support XML Content Types. There might be even use cases to support both XML and JSON Content Types at the same time. Integration Flows supports such advanced use cases.
API can be created to support multiple Content Types as shown below.
Integrations can be mapped for each operation – CRUD (POST, RETRIEVE, PUT, DELETE) for each resource as shown below.
For both XML and JSON content handling, for the integrations especially Create (POST) and Update (PUT) operations would require the below additional logic to be implemented.
- FLOW: getHTTPRequest – This step is a function to get the request Content-Type.
- IS Content-Type is XML – This step is a conditional block to identify if the request Content-Type is XML.
- XML: xmlNodeToDocument – This step is a function to convert the XML request content as a document.
Step 2 & 3 would only execute when of XML content used to invoke the integration and hence allow developers to create APIs that support both JSON and XML Content-Types.