Extract variables from an XML and JSON response messages. Assign variables to HTTP response headers.
This sample uses these policies:
Extract Variables: To pull subsets of data from the response body.
XML to JSON: To convert the response from XML to JSON.
Assign Message: To assign extracted data to response headers.
Reads extracted variables so they are visible in the Trace tool.
- Extract variables from the XML response sent from the target. Use XPath syntax to identify the data to extract.
- Use JavaScript policy to read the variables. This allows them to show up in the Trace tool.
- Convert the response payload from XML to JSON.
- Extract more variables from the converted JSON payload. Use JSONPath syntax to identify the data to extract.
- Use JavaScript policy to read the variables. This allows them to show up in the Trace tool.
- Assign the extracted variables to HTTP response headers.
-
Edit this script with your environment details:
api-platform-samples/setup/setenv.sh
-
./deploy.sh
-
invoke.sh
The proxy returns these custom headers to the client:
mock.city: San Jose mock.state: CA mock.firstName: John mock.lastName: Doe
See the main project README file for more detailed information about setting up, deploying, and invoking sample proxies.
This screen shot from the Apigee Edge trace tool shows the placement of the policies used in this sample.
Related policies
Related topics
- Variables reference
- Introduction to flow variables
- Video: Using Extract Variables policy
- Video: Extracting variables from XML and JSON messages
Copyright © 2016 Apigee Corporation
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.