In a conditional flow,
policies are executed only if the flow's condition evaluates totrue(as opposed to policies attached to the PreFlow or PostFlow,
which are always executed). This section describes how to create a conditional flow.
About conditional flows
During the processing of a request and response, only one conditional flow is executed per
segment—the first flow whose condition evaluates totrue.
You can create conditions that include||(OR) and&&(AND) operators. However, by default, the||operator has higher precedence than the&&operator. For example, a condition written
asA && B || C && Dis evaluated asA && (B || C) && D. Make sure to
parenthesize the expression if you want to change the precedence when using these operators.
The following examples illustrate some ways to use conditional flows.
Example 1
The following ProxyEndpoint definition shows a conditional flow that is executed
by the ProxyEndpoint on anyHTTP GETrequest to the API proxy:
Notice that the condition references therequest.verbflow
variable. A flow variable is named references that hold state information associated
with an API transaction processed by Apigee. Apigee defines many state variables that you can
reference.
Example 2
If your
service backend provides weather reports and weather forecasts, your API might define two
conditional flows that map to those API
resources:/reportsand/forecasts. When an API call
includes one of those resources in the URL, the condition evaluates to true and the logic
attached to the conditional flow is executed.
App developers then access your resources by making requests to a URL in the form:
http://myAPIs.myCo.com/weather/reports
or:
http://myAPIs.myCo.com/weather/forecasts
In an API proxy, you can define a conditional flow that corresponds to a specific
resource:
In this example, you reference theproxy.pathsuffixflow variable,
which contains the suffix portion of the URL used to access the API proxy. You can then attach
different policies to the conditional flow for each resource.
Example: Creating a conditional flow
The next example:
Creates a conditional flow that executes only when the request message
is an HTTPGET.
Adds a policy to the new flow.
Adding a conditional flow
Apigee in Cloud console
To add a conditional flow:
Select theDeveloptab in the Proxy Editor.
SelectProxy endpoints > defaultin the left-hand pane.
Note:You may need to expand the visual editor in the right-hand pane to see all the
elements.
To do so, click and drag the divider between the visual editor and the text editor
down a little.
Click the+button above theResponsepane.
In theAdd conditional flowdialog, selectPath and verb, and in thePathfield, enter the path suffix that you want to be in the request path in order for
the conditional flow to execute. SeeExample 2above.
The conditional flow only executes if the request is
aGETrequest (but not forPUT,POST, etc.).
The new flow, calledFlow-1, now appears in theProxy Endpointpane.
The XML code for the new conditional flow is displayed in the text editor.
Now that you have created the conditional flow, you can attach a policy to it. The next example
adds a Quota policy, which restricts the number of request messages that an API proxy allows over
a period of time, to the flow:
In the left-hand pane, click the+button to the right ofPolicies.
In theCreate policydialog, click in theSelect policy typefield and
scroll down toTraffic Managementand selectQuota.
ClickCreateto create the policy.
Click the+button next toFlow-1in theRequestpane.
In theAdd policy stepdialog, click in theSelect existing policyfield
and selectQuota-1.
ClickAdd.
TheRequestpane now displays the flow and attached policy,Quota-1.
The text editor now displays a step containing theQuota-1policy in theFlow-1element of the XML:
With this configuration, the Quota policy will be enforced forGETrequests.
Requests of other types will not contribute to the maximum number of requests in the Quota policy.
Classic UI
To add a conditional flow, select theDeveloptab in the API proxy builder.
Clickin the desired endpoint.
TheNew Conditional Flowform lets you name the flow and configure a condition. In the
following example, you add a simple condition that evaluates the HTTP of the request message for
aGETverb (as opposed toPUT,POST, etc.) on any URI after the base path.
Once you have created a conditional flow, it is available for policy attachment. With the flow
selected, click the+ Stepicon in the request or response diagram to add a
new or existing policy to the flow.
By attaching the policy to the selected flow, you are configuring the API proxy to enforce the
Quota policy only for requests made to that flow URI and verb combination. For example, if you
attach the policy to thelearnflow in the request, the following XML is
generated in the text editor:
In this configuration, if aGETrequest comes in on the API proxy with a URI
pattern of .../issue/**(/issue/ with anything in the URI after the last forward
slash), quota is enforced on that API call.
Next steps
The following topics provide more detail about constructing conditions and using
variables:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-04 UTC."],[[["\u003cp\u003eConditional flows in Apigee execute policies only if their defined condition evaluates to \u003ccode\u003etrue\u003c/code\u003e, unlike PreFlow or PostFlow policies that always run.\u003c/p\u003e\n"],["\u003cp\u003eOnly one conditional flow per segment is executed during a request and response, specifically the first flow whose condition is met.\u003c/p\u003e\n"],["\u003cp\u003eConditional flows can be based on HTTP verbs like \u003ccode\u003eGET\u003c/code\u003e or URL resources like \u003ccode\u003e/reports\u003c/code\u003e and \u003ccode\u003e/forecasts\u003c/code\u003e, leveraging flow variables such as \u003ccode\u003erequest.verb\u003c/code\u003e and \u003ccode\u003eproxy.pathsuffix\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAdding a conditional flow can be done in either the New Proxy Editor or the Classic Proxy Editor, allowing for customized execution logic based on specific request characteristics.\u003c/p\u003e\n"],["\u003cp\u003ePolicies, like a Quota policy, can be attached to a conditional flow to enforce certain rules, such as limiting request frequency, for requests matching the flow's condition.\u003c/p\u003e\n"]]],[],null,["# Conditional flows\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\nIn a conditional flow,\npolicies are executed only if the flow's condition evaluates to\n`true` (as opposed to policies attached to the PreFlow or PostFlow,\nwhich are always executed). This section describes how to create a conditional flow.\n\nAbout conditional flows\n-----------------------\n\nDuring the processing of a request and response, only one conditional flow is executed per\nsegment---the first flow whose condition evaluates to `true`.\nYou can create conditions that include `||`(OR) and `&&`(AND) operators. However, by default, the `||` operator has higher precedence than the `&&` operator. For example, a condition written as ` A && B || C && D` is evaluated as `A && (B || C) && D`. Make sure to parenthesize the expression if you want to change the precedence when using these operators.\n\nThe following examples illustrate some ways to use conditional flows.\n\n### Example 1\n\nThe following ProxyEndpoint definition shows a conditional flow that is executed\nby the ProxyEndpoint on any `HTTP GET` request to the API proxy: \n\n```text\n\u003cProxyEndpoint name=\"default\"\u003e\n \u003cPreFlow\u003e\n \u003cRequest/\u003e\n \u003cResponse/\u003e\n \u003c/PreFlow\u003e\n \u003cFlows\u003e\n \u003cFlow name=\"Flow-1\"\u003e\n \u003cCondition\u003erequest.verb=\"GET\"\u003c/Condition\u003e\n \u003cRequest/\u003e\n \u003cResponse/\u003e\n \u003c/Flow\u003e\n \u003c/Flows\u003e\n \u003cPostFlow\u003e\n \u003cRequest/\u003e\n \u003cResponse/\u003e\n \u003c/PostFlow\u003e\n ...\n\u003c/ProxyEndpoint\u003e\n```\n\nNotice that the condition references the `request.verb`\n[*flow\nvariable*](/apigee/docs/api-platform/fundamentals/introduction-flow-variables). A flow variable is named references that hold state information associated\nwith an API transaction processed by Apigee. Apigee defines many state variables that you can\nreference.\n\n### Example 2\n\nIf your\nservice backend provides weather reports and weather forecasts, your API might define two\nconditional flows that map to those API\nresources: `/reports` and `/forecasts`. When an API call\nincludes one of those resources in the URL, the condition evaluates to true and the logic\nattached to the conditional flow is executed.\n\nApp developers then access your resources by making requests to a URL in the form: \n\n```text\nhttp://myAPIs.myCo.com/weather/reports\n```\n\nor: \n\n```text\nhttp://myAPIs.myCo.com/weather/forecasts\n```\n\nIn an API proxy, you can define a conditional flow that corresponds to a specific\nresource: \n\n```text\n\u003cProxyEndpoint name=\"default\"\u003e\n \u003cPreFlow\u003e\n \u003cRequest/\u003e\n \u003cResponse/\u003e\n \u003c/PreFlow\u003e\n \u003cFlows\u003e\n \u003cFlow name=\"Flow-1\"\u003e\n \u003cCondition\u003e(proxy.pathsuffix MatchesPath \"/reports\")\u003c/Condition\u003e\n \u003cRequest/\u003e\n \u003cResponse/\u003e\n \u003c/Flow\u003e\n \u003cFlow name=\"Flow-2\"\u003e\n \u003cCondition\u003e(proxy.pathsuffix MatchesPath \"/forecasts\")\u003c/Condition\u003e\n \u003cRequest/\u003e\n \u003cResponse/\u003e\n \u003c/Flow\u003e\n \u003c/Flows\u003e\n \u003cPostFlow\u003e\n \u003cRequest/\u003e\n \u003cResponse/\u003e\n \u003c/PostFlow\u003e\n ...\n\u003c/ProxyEndpoint\u003e\n```\n\nIn this example, you reference the `proxy.pathsuffix` flow variable,\nwhich contains the suffix portion of the URL used to access the API proxy. You can then attach\ndifferent policies to the conditional flow for each resource.\n\nExample: Creating a conditional flow\n------------------------------------\n\nThe next example:\n\n- Creates a conditional flow that executes only when the request message is an HTTP `GET`.\n- Adds a policy to the new flow.\n\n### Adding a conditional flow\n\n### Apigee in Cloud console\n\nTo add a conditional flow:\n\n1. Select the **Develop** tab in the Proxy Editor.\n2. Select **Proxy endpoints \\\u003e default** in the left-hand pane.\n\n **Note:** You may need to expand the visual editor in the right-hand pane to see all the\n elements.\n To do so, click and drag the divider between the visual editor and the text editor\n down a little.\n3. Click the **+** button above the **Response** pane.\n\n4. In the **Add conditional flow** dialog, select **Path and verb** , and in the **Path** field, enter the path suffix that you want to be in the request path in order for the conditional flow to execute. See [Example 2](#example-2) above. **Note:** If you don't want to include a path condition, simply enter **/** in the **Path** field, as shown below. This will be matched for any request.\n\n The conditional flow only executes if the request is\n a `GET` request (but not for `PUT`, `POST`, etc.).\n\n The new flow, called `Flow-1`, now appears in the **Proxy Endpoint** pane.\n\n5. The XML code for the new conditional flow is displayed in the text editor.\n\nYou can edit the **Condition** element if you wish. See\n[Adding logic\nto flows](/apigee/docs/api-platform/fundamentals/what-are-flows#addinglogictoflows).\n\n### Attaching a policy to the flow\n\nNow that you have created the conditional flow, you can attach a policy to it. The next example\nadds a Quota policy, which restricts the number of request messages that an API proxy allows over\na period of time, to the flow:\n\n1. In the left-hand pane, click the **+** button to the right of **Policies**.\n2. In the **Create policy** dialog, click in the **Select policy type** field and scroll down to **Traffic Management** and select **Quota**.\n3. Click **Create** to create the policy.\n4. Click the **+** button next to **Flow-1** in the **Request** pane.\n\n5. In the **Add policy step** dialog, click in the **Select existing policy** field and select **Quota-1**.\n6. Click **Add**.\n\nThe **Request** pane now displays the flow and attached policy, **Quota-1**.\n\nThe text editor now displays a step containing the **Quota-1** policy in the\n**Flow-1** element of the XML:\n\nWith this configuration, the Quota policy will be enforced for `GET` requests.\nRequests of other types will not contribute to the maximum number of requests in the Quota policy.\n\n### Classic UI\n\nTo add a conditional flow, select the **Develop** tab in the API proxy builder.\n\nClick in the desired endpoint.\n\nThe **New Conditional Flow** form lets you name the flow and configure a condition. In the\nfollowing example, you add a simple condition that evaluates the HTTP of the request message for\na `GET` verb (as opposed to `PUT`, `POST`, etc.) on any URI after the base path.\n\n(Learn how to construct conditional statements in\n[Conditions with\nflow variables](/apigee/docs/api-platform/fundamentals/flow-variables-and-conditions).)\n\nThe new flow, called `Flow-1`, now appears in the Navigator menu.\n\nNow observe the XML configuration for the ProxyEndpoint. Select **Flow-1** in the\n**Navigator** menu.\n\nYou will see the following configuration. \n\n```scdoc\n\u003cPreFlow name=\"PreFlow\"\u003e\n \u003cRequest/\u003e\n \u003cResponse/\u003e\n\u003c/PreFlow\u003e\n\u003cFlows\u003e\n \u003cFlow name=\"Flow-1\"\u003e\n \u003cRequest/\u003e\n \u003cResponse/\u003e\n \u003cCondition\u003e(proxy.pathsuffix MatchesPath \"/**\") and (request.verb = \"GET\")\u003c/Condition\u003e\n \u003c/Flow\u003e\n\u003c/Flows\u003e\n\u003cPostFlow name=\"PostFlow\"\u003e\n \u003cRequest/\u003e\n \u003cResponse/\u003e\n\u003c/PostFlow\u003e\n```\n\nOnce you have created a conditional flow, it is available for policy attachment. With the flow\nselected, click the **+ Step** icon in the request or response diagram to add a\nnew or existing policy to the flow.\n\nBy attaching the policy to the selected flow, you are configuring the API proxy to enforce the\nQuota policy only for requests made to that flow URI and verb combination. For example, if you\nattach the policy to the **learn** flow in the request, the following XML is\ngenerated in the text editor: \n\n```scdoc\n\u003cProxyEndpoint name=\"default\"\u003e\n...\n \u003cFlow name=\"issue\"\u003e\n \u003cDescription/\u003e\n \u003cRequest\u003e\n \u003cStep\u003e\n \u003cName\u003eQuota-2\u003c/Name\u003e\n \u003c/Step\u003e\n \u003c/Request\u003e\n \u003cResponse/\u003e\n \u003cCondition\u003e(proxy.pathsuffix MatchesPath \"/issue/**\") and (request.verb = \"GET\")\u003c/Condition\u003e\n \u003c/Flow\u003e\n...\n\u003c/ProxyEndpoint\u003e\n```\n\nIn this configuration, if a `GET` request comes in on the API proxy with a URI\npattern of ...**/issue/\\*\\*** (/issue/ with anything in the URI after the last forward\nslash), quota is enforced on that API call.\n\nNext steps\n----------\n\nThe following topics provide more detail about constructing conditions and using\nvariables:\n\n- [Using flow variables](/apigee/docs/api-platform/fundamentals/introduction-flow-variables)\n- [Conditions with flow variables](/apigee/docs/api-platform/fundamentals/flow-variables-and-conditions)"]]