Apigee ti consente di programmare il comportamento delle API senza scrivere codice utilizzando i criteri. Un criterio è come un modulo che implementa una funzione di gestione specifica e limitata. I criteri sono progettati per consentirti di aggiungere in modo efficiente e affidabile tipi comuni di funzionalità di gestione a un'API.
I criteri forniscono funzionalità come sicurezza, limitazione di frequenza, trasformazione e mediazione, evitando di dover creare e gestire il codice autonomamente. Non sei limitato al set di tipi di norme fornito da Apigee. Puoi anche scrivere codice e script personalizzati (ad esempio applicazioni JavaScript) che estendono la funzionalità del proxy API e ti consentono di innovare al di sopra delle funzionalità di gestione di base supportate dai criteri Apigee.
Per creare un criterio utilizzando Apigee in Cloud Code:
Nello spazio di lavoro Apigee, esegui una delle seguenti azioni in base a dove vuoi allegare il criterio:
Collega a
Azione
proxy API
Esegui una delle seguenti azioni:
Posiziona il cursore del mouse su una delle seguenti cartelle, fai clic su e seleziona Crea norma:
apiproxy-name proxy bundle
apiproxy-name/apiproxy
Posiziona il cursore sulla cartella apiproxy-name/apiproxy/policies per il proxy API e fai clic su .
Flusso condiviso
Esegui una delle seguenti azioni:
Posiziona il cursore del mouse su una delle seguenti cartelle, fai clic su e seleziona Crea norma:
sharedflow-name bundle di flussi condivisi
sharedflow-name/sharedflowbundle
Posiziona il cursore sulla cartella sharedflow-name/sharedflowbundle/policies per il flusso condiviso e fai clic su .
Si apre la procedura guidata Crea policy.
Seleziona dall'elenco la categoria delle norme che vuoi creare.
Per una descrizione delle categorie di norme, vedi Panoramica del riferimento alle norme.
Inserisci un nome univoco per il criterio e premi Invio.
Il criterio viene aggiunto alla cartella /policies per il proxy API o il flusso condiviso nella sezione Apigee e aperto nell'editor.
Modifica il file in base alle esigenze e seleziona File > Salva o ⌘S per salvare le modifiche.
Per ulteriori informazioni sulla configurazione della policy, consulta la panoramica del riferimento alle policy.
Crea risorse, se richieste dal tipo di policy, come descritto in Gestione delle risorse.
Collegamento di un criterio a un flusso
Le policy non vengono eseguite finché non vengono associate a un flusso. Puoi collegare un criterio a un flusso aggiungendo l'elemento <Step> all'elemento di flusso di richiesta o risposta appropriato in una configurazione ProxyEndpoint o TargetEndpoint, come descritto nei seguenti argomenti:
Ad esempio, la seguente configurazione associa un QuotaPolicy a <PreFlow> di ProxyEndpoint per configurare il numero di messaggi di richiesta consentiti da un proxy API in un periodo di tempo.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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```"]]