This page applies to Apigeeand Apigee hybrid.
View Apigee Edge
documentation.
Apigee policies can transform message formats, enforce access control, call remote services, authorize users, examine message content for potential threats, and do much more. For more information, see What's a policy?
Proxy and target endpoints define a pipeline for request and response message processing referred to as request and response flows . Flows are sequential stages along the API request processing path. Policies are attached at different points in the request and response message flows as processing steps .
In the following steps, you create a new policy and attach it to your API proxy in the PreFlow
response flow to ensure the policy is applied before any other processing takes place. The XMLtoJSON policy
used in this tutorial converts the payload of the API's response message from XML to JSON.
- Create an XMLtoJSON policy.
- Expand the helloworld
API proxy bundle, position your cursor over the policies
folder, and click
. 
The Create policy wizard opens.
- Select Mediation as the policy category.
- Select XML to JSON as the policy type.
- Enter XMLtoJSON
as the policy name and click Enter
.
The policy is added to the
/policiesfolder for the API proxy and opened in the editor. - Click
XMLtoJSON.xmlto edit the policy. Set the<OutputVariable>and<Source>elements toresponseand save your changes.<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <XMLToJSON async="false" continueOnError="false" enabled="true" name="XMLtoJSON"> <DisplayName>XMLtoJSON</DisplayName> <Properties/> <Format>yahoo</Format> <OutputVariable> response </OutputVariable> <Source> response </Source> </XMLToJSON>
- Expand the helloworld
API proxy bundle, position your cursor over the policies
folder, and click
- Attach the policy to the default proxy endpoint.
- Expand the proxies folder in the helloworld API proxy bundle and click default.xml to open the file in the editor.
- Add a
<Step>element that references the XMLtoJSON policy to the<Response>flow in the API proxy<PreFlow>:<ProxyEndpoint name="default"> <PreFlow name="PreFlow"> <Request> <Step> <Name>verify-api-key</Name> </Step> <Step> <Name>remove-query-param-apikey</Name> </Step> <Step> <Name>impose-quota</Name> </Step> </Request> <Response> <Step> <Name>XMLtoJSON</Name> </Step> </Response> </PreFlow> ... </ProxyEndpoint>
- Save your changes to the file.
- To redeploy the environment, position your cursor over the dev
environment folder and click
. 
- When prompted to select a test bundle to export, click Deploy without a test bundle
because the test bundle has already been exported.

- Call your API in the Terminal
tab.
curl 0:8998/helloworld?apikey=ZQA5euYtNeJ7ZCGCJMpvd6F2BZOmxOzY
The XML response is converted to JSON, as follows:
{ "root": { "city": "San Jose", "firstName": "John", "lastName": "Doe", "state": "CA" } }
Congratulations! You've successfully attached the XMLtoJSON policy to your API proxy!
Next, you will deploy your API as an archive to an Apigee environment for integration testing and production release.
1 2 3 4 5 6 (NEXT) Step 7: Deploy to an Apigee environment 8

