API Mapping
The request and response of API need not be in the same format always. To provide a mapping between request and response, transformation policies are required. Fiorano API management uses Transformation policies to achieve this.
Transformation policy enables the transformation of messages of a particular format to another format such as XML, JSON, and plain text.
The policies in the Transformation category listed below are used to integrate applications that support a particular format, but require different formats for the same data:
- XML to JSON
- JSON to XML
- XML to XML
- Assign Variables
- Build Message
- Fault Handling
XML to JSON and JSON to XML
These policies allow users to convert the request/response from XML format to JSON format and vice-versa.
Using JSON to XML and XML to JSON policies, a JSON API can be exposed for Legacy/SOAP services that natively support only XML.
Also an API can be configured to support both JSON and XML formats by configuring JSON to XML and XML to JSON policies to execute conditionally (based on an Accept header value).
XML to XML
The XML2XML policy allows a user to configure source and target document structures using the Fiorano Mapper tool and create an XSL used for transforming documents. Alternatively, it allows users to define XSL created using external tools. Documents passed to the component are transformed using the XSL defined.
Assign Variables
The Assign Variable policy can be used to parse the message body to make various parts of the message available as variables that can be used in the proxy pipeline.
The message body could be any of the following:
- request to a proxy
- response from the target server
- response from any external service call outs
For example, a service call made to Google Location JSON service can be parsed to obtain latitude and longitude values. These values can be assigned to variables which in turn can be used to build Google Maps URLs using a Build Message policy. variables latitude and longitude of a location and can be used in the flow to build a request to the target server/another service call or response to the client.
This policy is preferred for simple transformations on huge data when used along with the Build Message policy. For complex transformations, policies or combination of those policies are listed below:
- XML to JSON
- XML to XML
- JSON to XML
Build Message
The Build Message policy provides a way to build various parts of a message using the Context Variables available in the flow.
Various parts of the request such as Payload, Target URL, Headers, Query parameters and Form parameters can be modified using this policy. The populated message can, in turn, be sent to the Target Server or to a Service Call Out policy for invocation. Similarly, the response to be sent back to the client can be customized using this policy.
Fault Handling
The Fault Handling policy provides a way to customize the error response and to remove sensitive information in the data that is sent back to the client.
The rules configured in the policy define conditions based on which it is possible to determine when a policy has to be executed at runtime.
This policy is an extension of the Build Message policy and helps in setting the error response code and error response phrase.