Puoi fare in modo che i flussi condivisi eseguano la pre-elaborazione delle richieste standard o la post-elaborazione delle risposte in un insieme di API. Con un hook di flusso, colleghi un flusso condiviso in modo che
venga eseguito nello stesso punto per tutti i proxy API di cui è stato eseguito il deployment in un ambiente specifico. In questo modo
ottieni una sequenza di logica implementata e distribuita separatamente che non fa parte del codice di implementazione di un proxy.
Poiché il codice collegato a un hook di flusso si trova al di fuori del contesto della logica principale del proxy API, alcuni
dei suoi comportamenti differiscono da quelli dei proxy API. Tieni presente che:
Devi disporre dell'autorizzazione per collegare un flusso condiviso a un hook di flusso. Devi essere un amministratore
dell'organizzazione.
Puoi collegare un solo flusso condiviso a ogni hook di flusso.
Puoi collegare lo stesso flusso condiviso a più hook di flusso.
Se un flusso condiviso collegato a un hook del flusso genera un errore o si verificano errori durante l'esecuzione del flusso condiviso, il messaggio verrà rifiutato e l'errore verrà restituito al chiamante.
Se un messaggio viene rifiutato durante l'esecuzione di un hook di flusso, i dettagli verranno registrati in
Analytics nel contesto del proxy chiamato. Il flusso condiviso può anche generare un errore con un
codice personalizzato e un messaggio di errore
Il seguente video mostra come collegare un flusso condiviso a un hook di flusso, quindi tracciarlo,
nella UI di Apigee.
Un flusso condiviso collegato a un proxy tramite un hook di flusso è un ottimo posto per la logica che
applica requisiti di policy generali. Ad esempio, supponiamo che un team gestisca un singolo
insieme di requisiti di sicurezza per più team che rappresentano diverse linee di business
(LOB). Ogni team LOB può sviluppare API in base ai propri requisiti e senza dover tenere conto dei requisiti di sicurezza più ampi. Il team di sicurezza può implementare questi requisiti di sicurezza in un flusso condiviso, quindi collegare il flusso all'ambiente Apigee utilizzando un hook di flusso. Poiché il flusso condiviso non fa parte del codice proxy, il team di sicurezza può rivederlo in base alle esigenze
senza interferire con il codice LOB.
I flussi condivisi collegati tramite hook di flusso vengono eseguiti in quella posizione per ogni proxy API di cui è stato eseguito il deployment
nell'ambiente dell'hook del proxy. Per questo motivo, la possibilità di utilizzare gli hook di flusso è disponibile
solo per gli amministratori di un'organizzazione Apigee.
Colleghi un flusso condiviso a un hook di flusso utilizzando la UI Apigee o l'API Flowhooks. Puoi
collegare al massimo un flusso condiviso a un hook di flusso in ciascuna delle seguenti posizioni:
Hook del flusso pre-proxy per la logica da applicare PRIMA dell'esecuzione di un endpoint proxy.
Ad esempio, potresti avere una logica per applicare la sicurezza a tutte le API in un
ambiente.
Hook del flusso pre-target per la logica da applicare PRIMA dell'esecuzione di un endpoint di destinazione.
Ad esempio, potresti implementare la registrazione prima che la richiesta raggiunga il backend. Puoi anche
imporre la mediazione rimuovendo determinati campi dalla richiesta.
Hook del flusso post-target per la logica da applicare DOPO l'esecuzione della risposta target.
Questa operazione verrà applicata subito dopo la risposta del backend. Puoi utilizzarlo
per registrare la risposta del backend o eseguire una mediazione rimuovendo i campi sensibili dalla
risposta del backend.
Hook del flusso post-proxy per la logica da applicare DOPO l'endpoint proxy e
subito prima che la risposta venga inviata al client.
Ciò potrebbe includere una logica di applicazione per CORS, la registrazione della risposta o l'esecuzione di
alcuni mashup o formattazioni.
Collegamento di un flusso condiviso a un hook di flusso
Per collegare un flusso condiviso a un hook del flusso, devi essere un amministratore dell'organizzazione
che contiene il flusso condiviso.
Apigee nella console Cloud
Per collegare un flusso condiviso a un hook di flusso:
Nella console Google Cloud , vai alla pagina Gestione > Ambienti.
Il flusso condiviso sarà disponibile per tutti i proxy API e i flussi condivisi di cui è stato eseguito il deployment in un
ambiente di questa organizzazione. Non sarà disponibile dall'esterno dell'organizzazione.
Seleziona l'ambiente che vuoi modificare dall'elenco degli ambienti disponibili.
Fai clic sulla scheda Hook di flusso nella pagina Dettagli ambiente.
Viene visualizzata la visualizzazione Hook di flusso.
Nell'elenco degli hook di flusso, identifica l'hook di flusso a cui vuoi collegare il flusso condiviso.
L'hook del flusso che scegli dipende da dove vuoi che venga eseguito il flusso condiviso.
Posizione dell'hook del flusso
Descrizione
Pre-proxy
Esegue before un endpoint proxy
Pre-target
Viene eseguito prima dell'esecuzione di un endpoint di destinazione
Post-target
Esegue after dopo l'esecuzione della risposta di destinazione
Post-proxy
Viene eseguito dopo l'endpoint proxy e subito prima che la risposta venga inviata al
client
Nella casella di elenco dell'hook del flusso che hai scelto, seleziona il flusso condiviso da collegare.
Collega i flussi condivisi ad altri hook di flusso in base alle necessità.
Fai clic su Salva per collegare i flussi condivisi selezionati agli hook di flusso.
Apigee classico
Per collegare un flusso condiviso a un hook di flusso:
Il flusso condiviso sarà disponibile per tutti i proxy API e i flussi condivisi di cui è stato eseguito il deployment in un
ambiente di questa organizzazione. Non sarà disponibile dall'esterno dell'organizzazione.
Seleziona Amministrazione > Ambienti > Hook di flusso nella barra di navigazione a sinistra.
La visualizzazione Hook di flusso mostra:
Nell'elenco a discesa dell'ambiente, seleziona quello che vuoi modificare.
Nell'elenco degli hook di flusso, identifica l'hook di flusso a cui vuoi collegare il flusso condiviso.
L'hook del flusso che scegli dipende da dove vuoi che venga eseguito il flusso condiviso.
Posizione dell'hook del flusso
Descrizione
Pre-proxy
Esegue before un endpoint proxy
Pre-target
Viene eseguito prima dell'esecuzione di un endpoint di destinazione
Post-proxy
Viene eseguito dopo l'endpoint proxy e subito prima che la risposta venga inviata al
client
Post-target
Esegue after dopo l'esecuzione della risposta di destinazione
Posiziona il cursore sul punto di aggancio del flusso nell'elenco per visualizzare la colonna delle azioni.
Fai clic su createModifica.
Nella finestra di dialogo Flusso condiviso, seleziona il flusso condiviso che vuoi allegare nel menu
Flusso condiviso.
Fai clic su OK.
Collega i flussi condivisi ad altri hook di flusso in base alle necessità.
[[["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\u003eThis content explains how to use flow hooks in Apigee and Apigee hybrid to attach shared flows for pre-processing or post-processing across multiple APIs.\u003c/p\u003e\n"],["\u003cp\u003eFlow hooks allow administrators to attach a shared flow to execute at specific points (pre-proxy, pre-target, post-target, post-proxy) in every API proxy deployed to a given environment.\u003c/p\u003e\n"],["\u003cp\u003eAttaching a shared flow to a flow hook is done through the Apigee UI or Flowhooks API, and it requires organization administrator permissions.\u003c/p\u003e\n"],["\u003cp\u003eA shared flow attached to a flow hook executes outside the core API proxy logic, allowing for the centralized management of policies like security or logging that applies to multiple APIs.\u003c/p\u003e\n"],["\u003cp\u003eThe attached shared flows to flow hooks can throw faults with custom messages, if any error occurs during execution, and are logged in the context of the calling proxy.\u003c/p\u003e\n"]]],[],null,["# Attaching a shared flow using a flow hook\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\nYou can have shared flows perform boilerplate request pre-processing or response\npost-processing across a set of APIs. With a *flow hook*, you attach a shared flow so that\nit executes at the same place for all API proxies deployed to a specific environment. This gives\nyou a separately implemented and deployed sequence of logic that is not part of a proxy's\nimplementation code.\n| **Note:** Attaching a shared flow to a flow hook is an action that has a very broad effect. The attached shared flow will execute at the flow hook's point **for every proxy deployed to that environment**.\n\nBecause code attached to a flow hook is outside the context of the API proxy core logic, some\nof its behavior differs from API proxies. Keep the following in mind:\n\n- You must have permission to attach a shared flow to a flow hook. You must be an org admin.\n- You can attach only one shared flow to each flow hook.\n- You can attach the same shared flow to multiple flow hooks.\n- If a shared flow attached to a flow hook raises a fault or there are errors during shared flow execution, the message will be rejected and fault will be sent back to the caller.\n- If a message gets rejected during execution of a flow hook, details will be logged to analytics in the context of the called proxy. The shared flow can also throw a fault with a custom code and error message\n\n| **Note:** This video was recorded with a previous version of the Apigee UI; however, the concepts are still valid.\n\nThe following video demonstrates how to connect a shared flow to a flow hook, then trace it,\nin the Apigee UI.\n\nA shared flow attached to a proxy via a flow hook provides a great place for logic that\nenforces broad policy requirements. For example, imagine that you have one team managing a single\nset of security requirements for multiple teams that represent different lines of businesses\n(LOBs). Each LOB team can develop APIs according to their own requirements, and without needing\nto account for the broader security requirements. The security team can implement those security\nrequirements in a shared flow, then attach the flow to the Apigee environment using a flow\nhook. Because the shared flow isn't part of proxy code, the security team can revise it as needed\nwithout interfering with LOB code.\n\nShared flows attached via flow hooks execute at that position for **every API proxy deployed\nto the proxy hook's environment**. For this reason, the ability to use flow hooks is available\nonly to administrators of an Apigee organization.\n\nFor more about shared flows, see\n[Creating reusable shared flows](/apigee/docs/api-platform/fundamentals/shared-flows).\n\nYou attach a shared flow to a flow hook using the Apigee UI or [Flowhooks API](/apigee/docs/reference/apis/apigee/rest/v1/organizations.environments.flowhooks). You can\nattach at most one shared flow to a flow hook at each of the following places:\n\n- **Pre-proxy flow hook** for logic that needs to be enforced BEFORE a proxy endpoint\n executes.\n\n For example, you could have logic for enforcing security across all the APIs in an\n environment.\n- **Pre-target flow hook** for logic that needs to be enforced BEFORE a target endpoint\n executes.\n\n For example, you could implement logging before the request reaches the backend. You could\n also enforce mediation by removing certain fields from the request.\n-\n **Post-target flow hook** for logic that needs to be enforced AFTER the target response\n executes.\n\n This will be enforced right after the response comes back from the backend. You can use it\n to log the backend response or perform some mediation by removing sensitive fields from the\n backend response.\n- **Post-proxy flow hook** for logic that needs to be enforced AFTER the proxy endpoint and\n right before the response is sent out to the client.\n\n This could include some enforcement logic for CORS, logging the response, or performing\n some mashup or formatting.\n\n### Attaching a shared flow to a flow hook\n\nTo attach a shared flow to a flow hook, you must be an administrator in the organization\ncontaining the shared flow.\n**Note:** Attaching a shared flow to a flow hook is an action that has a very broad effect. The attached shared flow will execute at the flow hook's point **for every proxy deployed to that environment**. \n\n### Apigee in Cloud console\n\nTo attach a shared flow to a flow hook:\n\n1. In the Google Cloud console, go to the **Management \\\u003e Environments** page.\n\n [Go to Environments](https://console.cloud.google.com/apigee/environments)\n2. Select the organization containing your shared flow. See [Switching between your organizations](/apigee/docs/api-platform/get-started/switch-org).\n\n The shared flow will be available to any API proxies and shared flows deployed to an\n environment from this organization. It won't be available from outside this organization.\n3. Select the environment you wish to edit from the list of available environments.\n4. Click the **Flow hooks** tab on the **Environment details** page.\n\n The **Flow hooks** view displays.\n5. In the list of flow hooks, identify the flow hook to which you want to attach the shared flow. The flow hook you choose depends upon where you want the shared flow to be executed.\n\n6. In the list box of the flow hook you chose, select the shared flow that you want to attach.\n7. Attach shared flows to other flow hooks as needed.\n8. Click **Save** to attach the selected shared flows to the flow hooks.\n\n### Classic Apigee\n\nTo attach a shared flow to a flow hook:\n\n1. Sign in to [Apigee UI](https://apigee.google.com).\n2. Select the organization containing your shared flow. See [Switching between your organizations](/apigee/docs/api-platform/get-started/switch-org).\n\n The shared flow will be available to any API proxies and shared flows deployed to an\n environment from this organization. It won't be available from outside this organization.\n3. Select **Admin \\\u003e Environments \\\u003e Flow hooks** in the left navigation bar.\n\n The **Flow hooks** view displays:\n\n4. From the environment drop-down list, select the environment that you want to modify.\n5. In the list of flow hooks, identify the flow hook to which you want to attach the shared flow. The flow hook you choose depends upon where you want the shared flow to be executed.\n\n6. Position your cursor over the flow hook in the list to display the actions column.\n7. Click create **Edit**.\n8. In the **Shared Flow** dialog, select the shared flow that you want to attach in the **Shared flow** menu.\n9. Click **OK**.\n10. Attach shared flows to other flow hooks as needed."]]