Os fluxos compartilhados executam pré-processamento de solicitações boilerplate ou pós-processamento de respostas em
um conjunto de APIs. Com um gancho de fluxo, você anexa um fluxo compartilhado para que
ele seja executado no mesmo lugar para todos os proxies de API implantados em um ambiente específico. Isso gera uma
sequência de lógica implementada e implantada separadamente que não faz parte do código de implementação
de um proxy.
Como o código anexado a um gancho de fluxo está fora do contexto da lógica principal do proxy de API, parte do
comportamento dele é diferente dos proxies de API. Lembre-se:
Você precisa ter permissão para anexar um fluxo compartilhado a um gancho de fluxo. Você precisa ser um administrador da
organização.
É possível anexar apenas um fluxo compartilhado a cada gancho de fluxo.
É possível anexar o mesmo fluxo compartilhado a vários ganchos de fluxo.
Se o fluxo compartilhado anexado a um gancho de fluxo gerar uma falha ou houver erros durante a execução do fluxo
compartilhado, a mensagem será rejeitada e a falha será enviada ao autor da chamada.
Se uma mensagem for rejeitada durante a execução de um gancho de fluxo, os detalhes serão registrados na
análise no contexto do proxy chamado. O fluxo compartilhado também pode gerar uma falha com um
código personalizado e uma mensagem de erro
O vídeo a seguir demonstra como conectar um fluxo compartilhado a um gancho de fluxo e rastreá-lo na
IU da Apigee.
Um fluxo compartilhado anexado a um proxy por meio de um gancho de fluxo é um ótimo lugar para lógica que
impõe requisitos amplos de política. Por exemplo, imagine que você tenha uma equipe gerenciando um único
conjunto de requisitos de segurança para várias equipes que representam linhas diferentes de empresas
(LOBs, na sigla em inglês). Cada equipe do LOB pode desenvolver APIs de acordo com os próprios requisitos e sem precisar considerar
os requisitos de segurança mais amplos. A equipe de segurança pode implementar esses requisitos de
segurança em um fluxo compartilhado e, em seguida, anexá-los ao ambiente da Apigee usando um gancho de
fluxo. Como o fluxo compartilhado não faz parte do código proxy, a equipe de segurança pode analisá-lo conforme necessário
sem interferir no código do LOB.
Os fluxos compartilhados anexados por meio de ganchos de fluxo são executados nessa posição para todos os proxies de API implantados
no ambiente do gancho de proxy. Por esse motivo, a capacidade de usar ganchos de fluxo está disponível
apenas para administradores de uma organização da Apigee.
Você anexa um fluxo compartilhado a um gancho de fluxo usando a IU da Apigee ou a API Flowhooks. É possível
anexar no máximo um fluxo compartilhado a um gancho de fluxo em cada um dos locais a seguir:
Gancho de fluxo pré-proxy para lógica que precisa ser aplicada ANTES da execução de um endpoint
de proxy.
Por exemplo, é possível ter lógica para impor a segurança em todas as APIs em um
ambiente.
Gancho de fluxo pré-destino para lógica que precisa ser aplicada ANTES da execução de um endpoint de
destino.
Por exemplo, é possível implementar a geração de registros antes que a solicitação chegue ao back-end. Também é possível
aplicar a mediação removendo determinados campos da solicitação.
Gancho de fluxo pós-destino para lógica que precisa ser aplicada APÓS a execução
da resposta.
Isso será aplicado logo após a resposta retornar do back-end. É possível usá-lo
para registrar a resposta de back-end ou executar uma mediação removendo campos confidenciais
dessa resposta.
Gancho de fluxo pós-proxy para a lógica que precisa ser aplicada APÓS o endpoint do proxy
e logo antes da resposta ser enviada ao cliente.
Isso pode incluir alguma lógica de aplicação para o CORS, registrar a resposta ou executar um mashup
ou formatação.
Como anexar um fluxo compartilhado a um gancho de fluxo
Para anexar um fluxo compartilhado a um gancho de fluxo, é necessário ser um administrador na organização
que contém o fluxo compartilhado.
Apigee no console do Cloud
Para adicionar um fluxo compartilhado a um hook de fluxo:
O fluxo compartilhado estará disponível para todos os proxies de API e fluxos compartilhados
implantados em um ambiente dessa organização. Ele não estará disponível fora desta organização.
No painel de navegação à esquerda, clique em Gerenciamento > Ambientes.
Na lista de ambientes disponíveis, selecione aquele que você quer editar.
Clique na guia Hooks de fluxo na página Detalhes do ambiente.
A visualização Hooks de fluxo é exibida.
Na lista de hooks de fluxo, localize o hook ao qual você quer anexar o fluxo compartilhado.
O hook de fluxo escolhido depende de onde você quer que o fluxo compartilhado seja executado.
Local do hook de fluxo
Descrição
Pré-proxy
Executa antes da execução de um endpoint de proxy.
Pré-destino
Executa antes da execução de um endpoint de destino.
Pós-destino
Executa depois que a resposta de destino é executada.
Pós-proxy
Executa depois do endpoint do proxy e logo antes da resposta ser enviada ao
cliente
Na caixa de listagem do hook de fluxo escolhido, selecione o fluxo compartilhado que você quer anexar.
Anexe fluxos compartilhados a outros hooks de fluxo conforme necessário.
Clique em Salvar para anexar os fluxos compartilhados selecionados aos hooks de fluxo.
Apigee clássica
Para adicionar um fluxo compartilhado a um hook de fluxo:
O fluxo compartilhado estará disponível para todos os proxies de API e fluxos compartilhados
implantados em um ambiente dessa organização. Ele não estará disponível fora desta organização.
Selecione Administrador > Ambientes > Hooks de fluxo na barra de navegação à esquerda.
A visualização Hooks de fluxo exibe o seguinte:
Na lista suspensa de ambiente, selecione o ambiente que você quer modificar.
Na lista de hooks de fluxo, localize o hook ao qual você quer anexar o fluxo compartilhado.
O hook de fluxo escolhido depende de onde você quer que o fluxo compartilhado seja executado.
Local do hook de fluxo
Descrição
Pré-proxy
Executa antes da execução de um endpoint de proxy.
Pré-destino
Executa antes da execução de um endpoint de destino.
Pós-proxy
Executa depois do endpoint do proxy e logo antes da resposta ser enviada ao
cliente
Pós-destino
Executa depois que a resposta de destino é executada.
Posicione o cursor sobre o gancho de fluxo na lista para exibir a coluna de ações.
Clique em createEditar.
Na caixa de diálogo Fluxo compartilhado, selecione o fluxo compartilhado que você quer anexar no menu
Fluxo compartilhado.
Clique em OK.
Anexe fluxos compartilhados a outros hooks de fluxo conforme necessário.
[[["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-08-18 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,["*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\nAttaching 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\nApigee 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\n | Flow hook location | Description |\n |--------------------|---------------------------------------------------------------------------------------------|\n | Pre-proxy | Executes *before* a proxy endpoint executes |\n | Pre-target | Executes *before* a target endpoint executes |\n | Post-target | Executes *after* the target response executes |\n | Post-proxy | Executes *after* the proxy endpoint and right before the response is sent out to the client |\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\nClassic 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\n | Flow hook location | Description |\n |--------------------|---------------------------------------------------------------------------------------------|\n | Pre-proxy | Executes *before* a proxy endpoint executes |\n | Pre-target | Executes *before* a target endpoint executes |\n | Post-proxy | Executes *after* the proxy endpoint and right before the response is sent out to the client |\n | Post-target | Executes *after* the target response executes |\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."]]