Com a Apigee, é possível programar o comportamento da API usando políticas, sem escrever nenhum código. Uma política é como um módulo que implementa uma função de gerenciamento específica e limitada. As políticas são projetadas para você adicionar tipos comuns de recursos de gerenciamento a uma API de maneira eficiente e confiável.
As políticas fornecem recursos como segurança, limitação de taxa, transformação e recursos de mediação, evitando que você precise criar e manter o código por conta própria. Você não está limitado ao conjunto de tipos de políticas fornecidos pela Apigee. Também é possível escrever scripts e códigos personalizados, como aplicativos JavaScript, que ampliam a funcionalidade do proxy de API e permitem que você inove os recursos básicos de gerenciamento compatíveis com as políticas da Apigee.
Para criar uma política usando a Apigee no Cloud Code:
No seu espaço de trabalho da Apigee, execute uma das seguintes ações com base no local em que quer anexar a política:
Anexar a
Ação
Proxy de API
Faça uma das seguintes ações:
Posicione o cursor sobre uma das seguintes pastas, clique em e selecione Criar política:
Pacote de proxy apiproxy-name
apiproxy-name/apiproxy
Posicione o cursor sobre a pasta apiproxy-name/apiproxy/policies do proxy de API e clique em .
Fluxo compartilhado
Faça uma das seguintes ações:
Posicione o cursor sobre uma das seguintes pastas, clique em e selecione Criar política:
pacote de fluxo compartilhado sharedflow-name
sharedflow-name/sharedflowbundle
Posicione o cursor sobre a pasta sharedflow-name/sharedflowbundle/policies no fluxo compartilhado e clique em .
O assistente "Criar política" é aberto.
Selecione a categoria da política que você quer criar na lista.
Para uma descrição das categorias de política, consulte Visão geral de referência da política.
Digite um nome exclusivo para a política e pressione Enter.
A política é adicionada à pasta /policies do proxy de API ou ao fluxo compartilhado na seção da Apigee e aberta no editor.
Edite o arquivo, conforme necessário, e selecione Arquivo > Salvar ou ⌘S para salvar suas edições.
Para mais informações sobre como configurar a política, consulte Visão geral de referência da política.
Crie recursos se exigido pelo tipo de política, conforme descrito em Como gerenciar recursos.
Como anexar uma política a um fluxo
As políticas não são executadas até que sejam anexadas a um fluxo. É possível anexar uma política a um fluxo adicionando o elemento <Etapa> ao elemento de fluxo de resposta ou solicitação apropriado em uma configuração ProxyEndpoint ou TargetEndpoint, conforme descrito nos tópicos a seguir:
Por exemplo, a configuração a seguir anexa uma QuotaPolicy ao <PreFlow> do ProxyEndpoint para configurar o número de mensagens de solicitação que um proxy de API permite durante um período de tempo.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-09-04 UTC."],[[["\u003cp\u003eApigee allows users to program API behavior without coding by using policies, which are modules that implement specific management functions.\u003c/p\u003e\n"],["\u003cp\u003ePolicies offer features like security, rate-limiting, transformation, and mediation, and can be extended with custom scripts and code.\u003c/p\u003e\n"],["\u003cp\u003ePolicies can be created and attached to API proxies or shared flows using Apigee in Cloud Code, with specific procedures outlined for each.\u003c/p\u003e\n"],["\u003cp\u003eCreating a policy involves selecting a policy category, giving the policy a unique name, and potentially creating resources depending on the policy type.\u003c/p\u003e\n"],["\u003cp\u003eTo be executed, policies must be attached to a flow by adding a \u003ccode\u003e<Step>\u003c/code\u003e element to the appropriate request or response flow in a ProxyEndpoint or TargetEndpoint configuration.\u003c/p\u003e\n"]]],[],null,["# Adding features using policies\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\n\u003cbr /\u003e\n\nApigee lets you program API behavior without writing any code by using *policies*. A policy is like a module that implements a specific, limited management function. Policies are designed to let you efficiently and reliably add common types of management capabilities to an API.\n\nPolicies provide features like security, rate-limiting, transformation, and mediation capabilities, saving you from having to build and maintain the code on your own. You're not limited to the set of policy types provided by Apigee. You can also write custom scripts and code (such as JavaScript applications) that extend API proxy functionality and enable you to innovate on top of the basic management capabilities supported by Apigee policies.\n\n[Create](#create) and [attach](#attach) policies to API proxies and shared flows using Apigee in Cloud Code as described in the following sections. Depending on the policy type, you may need to create a resource, as described in [Managing resources](/apigee/docs/api-platform/local-development/vscode/manage-resources). See also [Managing folders and files in an Apigee workspace](/apigee/docs/api-platform/local-development/vscode/manage-apigee-workspace#manage-folders-files).\n| **Before you begin** : Familiarize yourself with the concepts described in the following topics:\n|\n| - [What's a policy?](/apigee/docs/api-platform/develop/policy-attachment-and-enforcement)\n| - [Policy reference overview](/apigee/docs/api-platform/reference/policies/reference-overview-policy)\n| - [FlowCallout policy](/apigee/docs/api-platform/reference/policies/flow-callout-policy)\n\n### Creating a policy\n\nTo create a policy using Apigee in Cloud Code:\n\n1. In your Apigee workspace, perform one of the following actions based on where you want to attach the policy:\n\nThe Create policy wizard opens.\n\n1. Select the category of the policy that you want to create from the list.\n For a description of the policy categories, see [Policy reference overview](/apigee/docs/api-platform/reference/policies/reference-overview-policy).\n\n2. Enter a unique name for the policy and press **\u003ckbd\u003eEnter\u003c/kbd\u003e** .\n The policy is added to the `/policies` folder for the API proxy or shared flow in the Apigee section and opened in the editor.\n\n3. Edit the file, as required, and select **File \\\u003e Save** or ⌘S to save your edits.\n For more information about configuring the policy, see [Policy reference overview](/apigee/docs/api-platform/reference/policies/reference-overview-policy).\n\n4. Create resources if required by the policy type, as described in [Managing resources](/apigee/docs/api-platform/local-development/vscode/manage-resources).\n\n### Attaching a policy to a flow\n\nPolicies are not executed until they are attached to a flow. You can attach a policy to a flow by adding the **\\\u003cStep\\\u003e** element to the appropriate request or response flow element in a ProxyEndpoint or TargetEndpoint configuration, as described in the following topics:\n\n- [Attaching a policy to a ProxyEndpoint or TargetEndpoint flow](/apigee/docs/api-platform/develop/attaching-policy-proxyendpoint-or-targetendpoint-flow)\n- [FlowCallout policy](/apigee/docs/api-platform/reference/policies/flow-callout-policy)\n\nFor example, the following configuration attaches a [QuotaPolicy](/apigee/docs/api-platform/reference/policies/quota-policy) to the `\u003cPreFlow\u003e` of the ProxyEndpoint to configure the number of request messages that an API proxy allows over a period of time. \n\n```\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 \u003c/HTTPProxyConnection\u003e\n \u003cRouteRule name=\"default\"\u003e\n \u003cTargetEndpoint\u003edefault\u003c/TargetEndpoint\u003e\n \u003c/RouteRule\u003e\n\u003c/ProxyEndpoint\u003e\n```"]]