Anda dapat membuat alur bersama melakukan pra-pemrosesan permintaan boilerplate atau pasca-pemrosesan respons di seluruh rangkaian API. Dengan flow hook, Anda melampirkan alur bersama sehingga
dieksekusi di tempat yang sama untuk semua proxy API yang di-deploy ke lingkungan tertentu. Hal ini memberi Anda urutan logika yang diimplementasikan dan di-deploy secara terpisah yang bukan bagian dari kode implementasi proxy.
Karena kode yang dilampirkan ke hook alur berada di luar konteks logika inti proxy API, beberapa
perilakunya berbeda dari proxy API. Ingat hal berikut:
Anda harus memiliki izin untuk melampirkan alur bersama ke flow hook. Anda harus menjadi admin
organisasi.
Anda hanya dapat melampirkan satu alur bersama ke setiap hook alur.
Anda dapat melampirkan alur bersama yang sama ke beberapa hook alur.
Jika alur bersama yang terlampir ke hook alur memunculkan kesalahan atau terjadi error selama eksekusi alur bersama, pesan akan ditolak dan kesalahan akan dikirim kembali ke pemanggil.
Jika pesan ditolak selama eksekusi hook alur, detail akan dicatat ke
analisis dalam konteks proxy yang dipanggil. Alur bersama juga dapat memunculkan kesalahan dengan
kode dan pesan error kustom
Video berikut menunjukkan cara menghubungkan alur bersama ke hook alur, lalu melacaknya,
di UI Apigee.
Alur bersama yang dilampirkan ke proxy melalui hook alur menyediakan tempat yang tepat untuk logika yang
menerapkan persyaratan kebijakan yang luas. Misalnya, bayangkan Anda memiliki satu tim yang mengelola satu set persyaratan keamanan untuk beberapa tim yang mewakili berbagai lini bisnis (LOB). Setiap tim LOB dapat mengembangkan API sesuai dengan persyaratannya sendiri, dan tanpa perlu memperhitungkan persyaratan keamanan yang lebih luas. Tim keamanan dapat menerapkan persyaratan keamanan tersebut dalam alur bersama, lalu melampirkan alur ke lingkungan Apigee menggunakan hook alur. Karena alur bersama bukan bagian dari kode proxy, tim keamanan dapat merevisinya sesuai kebutuhan
tanpa mengganggu kode LOB.
Alur bersama yang dilampirkan melalui flow hook dijalankan di posisi tersebut untuk setiap proxy API yang di-deploy
ke lingkungan proxy hook. Oleh karena itu, kemampuan untuk menggunakan hook alur hanya tersedia bagi administrator organisasi Apigee.
Anda melampirkan alur bersama ke flow hook menggunakan UI Apigee atau Flowhooks API. Anda dapat melampirkan paling banyak satu alur bersama ke flow hook di setiap tempat berikut:
Hook alur pra-proxy untuk logika yang perlu diterapkan SEBELUM endpoint proxy
dieksekusi.
Misalnya, Anda dapat memiliki logika untuk menerapkan keamanan di semua API dalam
lingkungan.
Hook alur pra-target untuk logika yang perlu diterapkan SEBELUM endpoint target
dieksekusi.
Misalnya, Anda dapat menerapkan logging sebelum permintaan mencapai backend. Anda juga dapat menerapkan mediasi dengan menghapus kolom tertentu dari permintaan.
Hook alur pasca-target untuk logika yang perlu diterapkan SETELAH respons target dijalankan.
Hal ini akan diterapkan tepat setelah respons kembali dari backend. Anda dapat menggunakannya
untuk mencatat respons backend atau melakukan mediasi dengan menghapus kolom sensitif dari
respons backend.
Hook alur pasca-proxy untuk logika yang perlu diterapkan SETELAH endpoint proxy dan
tepat sebelum respons dikirim ke klien.
Hal ini dapat mencakup beberapa logika penerapan untuk CORS, mencatat respons, atau melakukan
beberapa mashup atau pemformatan.
Melampirkan alur bersama ke hook alur
Untuk melampirkan alur bersama ke hook alur, Anda harus menjadi administrator di organisasi
yang berisi alur bersama.
Apigee di Konsol Cloud
Untuk melampirkan alur bersama ke hook alur:
Di konsol Google Cloud , buka halaman Management > Environments.
Alur bersama akan tersedia untuk semua proxy API dan alur bersama yang di-deploy ke
lingkungan dari organisasi ini. Aplikasi tidak akan tersedia dari luar organisasi ini.
Pilih lingkungan yang ingin Anda edit dari daftar lingkungan yang tersedia.
Klik tab Flow hooks di halaman Environment details.
Tampilan Flow hooks akan ditampilkan.
Dalam daftar hook alur, identifikasi hook alur yang ingin Anda lampirkan alur bersama.
Hook alur yang Anda pilih bergantung pada tempat Anda ingin alur bersama dieksekusi.
Lokasi hook alur
Deskripsi
Pra-proxy
Menjalankan sebelum endpoint proxy dijalankan
Sebelum menargetkan
Dieksekusi sebelum endpoint target dieksekusi
Pasca-target
Mengeksekusi setelah respons target dieksekusi
Pasca-proxy
Mengeksekusi setelah endpoint proxy dan tepat sebelum respons dikirim ke
klien
Di kotak daftar hook alur yang Anda pilih, pilih alur bersama yang ingin Anda lampirkan.
Lampirkan alur bersama ke flow hook lain sesuai kebutuhan.
Klik Simpan untuk melampirkan alur bersama yang dipilih ke hook alur.
Alur bersama akan tersedia untuk semua proxy API dan alur bersama yang di-deploy ke
lingkungan dari organisasi ini. Aplikasi tidak akan tersedia dari luar organisasi ini.
Pilih Admin > Lingkungan > Hook alur di menu navigasi kiri.
Tampilan Flow hooks menampilkan:
Dari daftar drop-down lingkungan, pilih lingkungan yang ingin Anda ubah.
Dalam daftar hook alur, identifikasi hook alur yang ingin Anda lampirkan alur bersama.
Hook alur yang Anda pilih bergantung pada tempat Anda ingin alur bersama dieksekusi.
Lokasi hook alur
Deskripsi
Pra-proxy
Menjalankan sebelum endpoint proxy dijalankan
Sebelum menargetkan
Dieksekusi sebelum endpoint target dieksekusi
Pasca-proxy
Mengeksekusi setelah endpoint proxy dan tepat sebelum respons dikirim ke
klien
Pasca-target
Mengeksekusi setelah respons target dieksekusi
Posisikan kursor Anda di atas hook alur dalam daftar untuk menampilkan kolom tindakan.
Klik createEdit.
Pada dialog Shared Flow, pilih alur bersama yang ingin Anda lampirkan di menu
Shared flow.
Klik Oke.
Lampirkan alur bersama ke flow hook lain sesuai kebutuhan.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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."]]