[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-26。"],[[["\u003cp\u003eThis documentation applies to both Apigee and Apigee hybrid platforms.\u003c/p\u003e\n"],["\u003cp\u003ePolicies in Apigee are attached to Flows using a Step configuration within either a request or response flow, and are not executed unless attached.\u003c/p\u003e\n"],["\u003cp\u003eThe attachment point of a policy significantly impacts API proxy behavior, such as attaching a Quota policy to a request Flow to enforce it before any backend processing.\u003c/p\u003e\n"],["\u003cp\u003ePolicies can be attached to PreFlow or PostFlow within request and response Flows, allowing for sequential processing, as demonstrated in the examples.\u003c/p\u003e\n"],["\u003cp\u003eThe name provided to the policy within the step configuration must match exactly the name attribute in the corresponding policy file in the /policies folder.\u003c/p\u003e\n"]]],[],null,["# Attaching a policy to a ProxyEndpoint or TargetEndpoint Flow\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\nPolicies are not executed until they are attached to a Flow. You can create a Policy\nattachment by naming a Policy in a Step configuration.\n\nThe choice of attachment point is critical to the behavior of your API proxy. For example, if\nyou attach the Quota policy to a response Flow, then the Quota would be enforced *after* the\nrequest message was sent to the backend service. That would defeat the purpose of applying a\nQuota policy! Therefore, you need to attach the Quota policy as a processing Step on the request\nFlow.\n\nThe format of a policy attachment is: \n\n```scdoc\n\u003cStep\u003e\n \u003cName\u003e{policy_name}\u003c/Name\u003e\n\u003c/Step\u003e\n```\n\nFor example: \n\n```text\n\u003cStep\u003e\n \u003cName\u003eQuotaPolicy\u003c/Name\u003e\n\u003c/Step\u003e\n```\n| **Note:** The `{policy_name}` variable must be the same as the `name` attribute in the policy (stored under /policies) that you want to attach. The names must match exactly, as name matching is case-sensitive.\n\nA policy is attached to a Flow by adding the Step configuration to the appropriate request or\nresponse Flow element in a ProxyEndpoint or TargetEndpoint configuration.\n\nYou can attach a policy to a request or response Flow. Request and response Flows are further\nsubdivided in to PreFlow and PostFlow.\n\nThe following example demonstrates the minimal ProxyEndpoint configuration, with no policy\nattachments. It simply defines the (inbound) HTTPProxyConnection and a RouteRule. \n\n```text\n\u003cProxyEndpoint name=\"default\"\u003e\n \u003cHTTPProxyConnection\u003e\n \u003cBasePath\u003e/weather\u003c/BasePath\u003e\n \u003cVirtualHost\u003edefault\u003c/VirtualHost\u003e\n \u003c/HTTPProxyConnection\u003e\n \u003cRouteRule name=\"default\"\u003e\n \u003cTargetEndpoint\u003edefault\u003c/TargetEndpoint\u003e\n \u003c/RouteRule\u003e\n\u003c/ProxyEndpoint\u003e\n```\n\nYou must modify this configuration so that the ProxyEndpoint enforces a Quota policy (as a\nprocessing Step) before the API proxy performs any other processing. If a developer has exceeded\na Quota, you don't want to waste any computational resources on additional requests.\n\nTo enforce this configuration, you attach a processing Step to the request PreFlow as\nfollows: \n\n```text\n\u003cProxyEndpoint name=\"default\"\u003e\n \u003cPreFlow\u003e\n \u003cRequest\u003e\n \u003cStep\u003e\u003cName\u003eQuotaPolicy\u003c/Name\u003e\u003c/Step\u003e\n \u003c/Request\u003e\n \u003c/PreFlow\u003e\n \u003cHTTPProxyConnection\u003e \n \u003cBasePath\u003e/weather\u003c/BasePath\u003e \n \u003cVirtualHost\u003edefault\u003c/VirtualHost\u003e \n \u003c/HTTPProxyConnection\u003e \n \u003cRouteRule name=\"default\"\u003e \n \u003cTargetEndpoint\u003edefault\u003c/TargetEndpoint\u003e \n \u003c/RouteRule\u003e \n\u003c/ProxyEndpoint\u003e\n```\n\nSometimes, you might want a policy to execute after some other initial processing on the\nProxyEndpoint. For example, you want to check Quota in the PreFlow, then perform another set of\nprocessing after Quota is checked, such as converting the request from JSON to XML. To do so,\nattach a policy to the PostFlow request path. The following is a sample request PostFlow\nattachment. This policy would execute on the request message after all of the policies in the\nPreFlow (and any conditional flows) execute. \n\n```text\n\u003cPostFlow\u003e\n \u003cRequest\u003e\n \u003cStep\u003e\u003cName\u003eJSONtoXMLPolicy\u003c/Name\u003e\u003c/Step\u003e\n \u003c/Request\u003e\n\u003c/PostFlow\u003e\n```\n\nThe following is a sample response PostFlow attachment. This policy would execute on the\nresponse message. (The ProxyEndpoint response PostFlow is the final processing phase before the\nresponse is returned to the requesting client app.) \n\n```text\n\u003cPostFlow\u003e\n \u003cResponse\u003e\n \u003cStep\u003e\u003cName\u003eXMLtoJSONPolicy\u003c/Name\u003e\u003c/Step\u003e\n \u003c/Response\u003e\n\u003c/PostFlow\u003e\n```\n| **Tip:** You can also define conditional Flows that execute *between* the PreFlow and PostFlow phases. This is covered in the next topic, [Flow variables and\n| conditions](/apigee/docs/api-platform/fundamentals/flow-variables-and-conditions)."]]