Create a REST API that has a response in JSON format and publish the API.
- ColdFusion Tools User Guide
- Performance Monitoring Toolset
- Overview of ColdFusion Performance Monitoring Toolset
- Auto-discovery of ColdFusion nodes and clusters
- Code profiler in ColdFusion Performance Monitoring Toolset
- Configure ColdFusion Performance Monitoring Toolset settings
- Install ColdFusion Performance Monitoring Toolset
- View cloud metrics
- Monitor GraphQL in Performance Monitoring Toolset
- Configure TLS/SSL and Authentication for Elasticsearch 8.x in Performance Monitoring Toolset
- View cluster and node metrics
- View data source metrics
- View external services
- View incoming services
- View list of sites and busy connections
- View topology of sites
- Datastore Health Monitoring
- Performance Monitoring Toolset Update 1
- Secure Performance Monitoring Toolset with HTTPS/SSL
- Performance Monitoring Toolset deployment guide
- Use ColdFusion Builder
- About ColdFusion Builder
- System requirements | ColdFusion Builder
- Install ColdFusion Builder
- Edit code in ColdFusion Builder
- Manage servers in ColdFusion Builder
- Manage projects in ColdFusion Builder
- What's new in Adobe ColdFusion Builder (2018 release)
- Frequently Asked Questions (FAQ) | Adobe ColdFusion Builder (2018 release)
- Debug applications in ColdFusion Builder
- ColdFusion Builder workbench
- ColdFusion Builder extensions
- Debugging Perspective in ColdFusion Builder
- Build mobile applications using ColdFusion Builder
- Bundled ColdFusion Server
- Debug mobile applications in ColdFusion Builder
- Use extensions in ColdFusion Builder
- Coldfusion API Manager
- Overview of Adobe ColdFusion API Manager
- Features in ColdFusion API Manager
- Get started with ColdFusion API Manager
- Install ColdFusion API Manager
- Authentication types
- Create and publish APIs
- Administrator
- Subscriber
- Throttling and rate limiting
- Notifications
- Connectors
- Set up cluster support
- Integrate ColdFusion and API Manager
- Metrics and Logging in API Manager
- Generate Swagger documents
- Configure SSL
- Known issues in this release
- Policies in ColdFusion API Manager
- Create a Redis cluster
- Multitenancy in API Manager
- Docker images for ColdFusion API Manager
Policies in ColdFusion API Manager
In ColdFusion API Manager, policies allow you to change the behavior of an API by making certain configuration changes. Policies are a collection of commands that are executed sequentially at the request or response of an API.
In API Manager, there are two main categories of policies:
- Data transformation policies
- Threat protection policies
Using the Data Transformation policies
REST APIs created with ColdFusion supports multiple representations of a resource. ColdFusion APIs support both XML and JSON representations for the request and response payloads.
But there are APIs that do not support multiple representations. For example, an API may only support an XML payload. But a web application might want the response in a JSON format. Or vice-versa. In such cases, ColdFusion API Manager converts the JSON payload to an XML payload.
In other words, the data transformation policies let you transform the request/response payload from JSON to XML or from XML to JSON.
As an API creator and publisher, you can enforce these policies to an API and convert the responses to the appropriate format before sending a response to the client.
JSON to XML Transformation
To convert a JSON response to XML:
-
-
Click Policies in the left navigation panel and choose JSON to XML Transformation policy. Click Add Policy.
-
Enter the values in the fields. For more information, refer to the field descriptions.
-
Create the policy.
-
Click My APIs in the left navigation panel and click Edit API on the newly created API to modify the API properties.
-
Click Policies in the left navigation panel and drag the policy into the Response section and click Save.
-
To test the API, click Test this API.
-
Choose the resource and click Run API Call. You can see the result in the Response Body section.
{ "message": "Hello World", "names": [ "John", "Paul", "George" ], "address": { "street": "Bleecker street", "housenumber": 50 } }
The XML transformation is as follows:
<beatles> <message>Hello World</message> <address> <street>Bleecker street</street> <housenumber>50</housenumber> </address> <names>John</names> <names>Paul</names> <names>George</names> <?xml-multiple names?> </beatles>
XML to JSON Transformation
To convert an XML response to JSON:
-
Create a REST API that has a response in XML format and publish the API.
-
Click Policies in the left navigation panel and choose XML to JSON Transformation policy. Click Add Policy.
-
Enter the values in the fields. For more information, refer to the field descriptions.
-
Create the policy.
-
Click My APIs in the left navigation panel and click Edit API on the newly created API to modify the API properties.Step text
-
Click Policies in the left navigation panel and drag the policy into the Response section and click Save.
-
To test the API, click Test this API.
-
Choose the resources and click Run API Call. You can see the result in the Response Body section.
<?xml version="1.0" encoding="utf-8"?> <IncomeAndHouseValue xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ws.cdyne.com/DemographixWS"> <PlaceInformation> <StateAbbrev>NY</StateAbbrev> <PlaceID>0036146</PlaceID> <Rural>false</Rural> </PlaceInformation> <Error>false</Error> <ErrorString>No Error</ErrorString> <MedianIncome>61544</MedianIncome> <MedianHouseValue>283600</MedianHouseValue> </IncomeAndHouseValue>
The JSON transformation is as follows:
{ "IncomeAndHouseValue": { "@xmlns": "http://ws.cdyne.com/DemographixWS", "@xmlns:xsd": "http://www.w3.org/2001/XMLSchema", "@xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", "PlaceInformation": { "StateAbbrev": "NY", "PlaceID": 36146, "Rural": false }, "Error": false, "ErrorString": "No Error", "MedianIncome": 61544, "MedianHouseValue": 283600 } }
Using the Threat Protection policies
In this example, you will apply a JSON Structure policy on an API and validate the response.
Like most APIs that support XML-based services, APIs that support JSON are vulnerable to content-level attacks. Simple JSON attacks attempt to use structures that overwhelm JSON parsers to crash a service and induce application-level denial-of-service attacks. The JSON Document Structure feature validates and enforces constraints on the structure of JSON documents. When the structure of an incoming JSON document exceeds a specified constraint, the API Gateway rejects the JSON document with error 500 and blocks further processing of the policy.
To enforce JSON structure policy:
-
Create a REST API that has JSON as response. Publish the API.
-
Edit the API and add a POST operation to a resource.
-
Add a parameter of type BODY to the resource.
-
Save your changes.
-
Go back to the main view, choose Policies->Threat Protection, and choose JSON Structure Limits.
-
Enter the values, as shown below. Set the maximum key length of a JSON object as 2.
-
Click Policies in the left navigation panel and drag the newly created policy in the Request section.
-
Save the changes. To test the API against the policy, click Test this API in the left navigation panel. Expand the resource with POST and pass the following JSON into the body.
{ "names": [ "John", "Paul", "George" ], "address": { "street": "Bleecker street", "housenumber": 50 } }
-
Click Run API Call. You can see the appropriate response.