Attaching a shared flow using a flow hook

You're viewing Apigee Edge documentation.
Go to the Apigee X documentation.
info

You can have shared flows perform boilerplate request pre-processing or response post-processing across a set of APIs. With a flow hook, you attach a shared flow so that it executes at the same place for all API proxies deployed to a specific environment. This gives you a separately implemented and deployed sequence of logic that is not part of a proxy's implementation code.

Because code attached to a flow hook is outside the context of the API proxy core logic, some of its behavior differs from API proxies. Keep the following in mind:

  • You must have permission to attach a shared flow to a flow hook. You must be an org admin.
  • You can attach only one shared flow to each flow hook.
  • You can attach the same shared flow to multiple flow hooks.
  • If 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 caller.
  • 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

The following video demonstrates how to connect a shared flow to a flow hook, then trace it, in the Classic Edge UI.

The following video demonstrates how to connect a shared flow to a flow hook, then trace it, in the New Edge experience UI.

A shared flow attached to a proxy via a flow hook provides a great place for logic that enforces broad policy requirements. For example, imagine that you have one team managing a single set of security requirements for multiple teams that represent different lines of businesses (LOBs). Each LOB team can develop APIs according to their own requirements, and without needing to account for the broader security requirements. The security team can implement those security requirements in a shared flow, then attach the flow to the Apigee Edge environment using a flow hook. Because the shared flow isn't part of proxy code, the security team can revise it as needed without interfering with LOB code.

Shared flows attached via flow hooks execute at that position for every API proxy deployed to the proxy hook's environment. For this reason, the ability to use flow hooks is available only to administrators of an Apigee Edge org.

For more about shared flows, see Reusable shared flows.

You attach a shared flow to a flow hook using the Apigee Edge management console. You can attach at most one shared flow to a flow hook at each of the following places:

  • Pre-proxy Flow Hook for logic that needs to be enforced BEFORE a proxy endpoint executes.

    For example, you could have logic for enforcing security across all the APIs in an environment.

  • Pre-target Flow Hook for logic that needs to be enforced BEFORE a target is called.

    For example, you could implement logging before the request reaches the backend. You could also enforce mediation by removing certain fields from the request.

  • Post-target Flow Hook for logic that needs to be enforced AFTER the target response executes.

    This will be enforced right after the response comes back from the backend. You can use it to log the backend response or perform some mediation by removing sensitive fields from the backend response.

  • Post-proxy Flow Hook for logic that needs to be enforced AFTER the proxy endpoint and right before the response is sent out to the client.

    This could include some enforcement logic for CORS, logging the response, or performing some mashup or formatting.

Attaching a shared flow to a flow hook

To attach a shared flow to a flow hook, you must be an administrator in the organization containing the shared flow.

  1. Access the Flow Hooks page, as described below.

    Edge

    To access the Flow Hooks page using the Edge UI:

    1. Sign in to apigee.com/edge.
    2. Select the organization containing your shared flow. See Switching between your organizations.

      The shared flow will be available to any API proxies and shared flows deployed to an environment from this organization. It won't be available from outside this organization.

    3. Select Admin > Environments > Flow Hooks in the left navigation bar.

    Classic Edge (Private Cloud)

    To access the Flow Hooks page using the Classic Edge UI:

    1. Sign in to http://ms-ip:9000, where ms-ip is the IP address or DNS name of the Management Server node.
    2. Select the organization containing your shared flow. See Switching between your organizations.

      The shared flow will be available to any API proxies and shared flows deployed to an environment from this organization. It won't be available from outside this organization.

    3. Select APIs > Environment Configuration > Flow Hooks in the top navigation bar.
  2. In the list of flow hooks, identify the flow hook to which you want to attach the shared flow based on where you want the shared flow to be executed.
    Flow Hook Location Description
    Pre-proxy Flow Hook BEFORE a proxy endpoint executes
    Pre-target Flow Hook BEFORE a target endpoint executes
    Post-target Flow Hook AFTER the target response executes
    Post-proxy Flow Hook AFTER the proxy endpoint and right before the response is sent out to the client
  3. Position your cursor over the flow hook in the list to display the actions column.
  4. Click .
  5. In the Shared Flow dialog, select the shared flow that you want to attach in the Shared flow dropdown.
  6. Click OK.
  7. Attach shared flows to other flow hooks as needed.