Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
apiproxy update zip file based on changes to proxy Nov 30, 2016 use mocktarget Aug 3, 2016 update conditional policy example, and add back the "api_domain="apig… Nov 3, 2016

Conditional Policy Enforcement

Sample use case

Demonstrates conditional policy enforcement in an API proxy.


This sample uses this policy:

  • alt text Python Script: To add customized Python functionality to your API proxy.


This sample demonstrates conditional policy enforcement on the Apigee API Platform. Conditional policy enforcement enables you to execute a policy based on a condition defined on a flow.

The condition in this sample evaluates a custom HTTP header called "responsetime". When “true”, a Python script executes to populates custom response headers with metrics about the request. When "responsetime" is "false" or is omitted from the request, the Python script is bypassed and the metrics do not appear in the response.

For example, the following cURL command passes the "responsetime" header as "true":

curl -i -H "responsetime:true" "http://$org-$env.$api_domain/v1/timer"

The response body always contains the string "Hello, Guest!". When "responsetime" is "true", the response also contains the headers prefixed by "X-Apigee":

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Content-Type: text/plain; charset=utf-8
Date: Thu, 03 Nov 2016 13:42:18 GMT
ETag: W/"d-GHB1ZrJKk/wdVTdB/jgBsw"
Server: Apigee Router
X-Apigee-end-time: Thu, 3 Nov 2016 13:42:18 UTC
X-Apigee-end-timestamp: 1478180538275
X-Apigee-start-time: Thu, 3 Nov 2016 13:42:18 UTC
X-Apigee-start-timestamp: 1478180538088
X-Apigee-target-responseTime: 187
X-Powered-By: Apigee
Content-Length: 13
Connection: keep-alive

For a complete list of predefined variables and instructions on constructing conditional statements with those variables, see these topics in the Apigee docs:

Set up, deploy, invoke

See the main project README file for information about setting up, deploying, and invoking sample proxies.

To deploy, run $ sh

To test, run $ sh


This screen shot from the Apigee Edge trace tool shows the placement of the policies used in this sample.

alt text

More information

Policy used in this sample

Ask the community

alt text

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

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.

You can’t perform that action at this time.