Apigee memungkinkan Anda memprogram perilaku API tanpa menulis kode apa pun dengan menggunakan kebijakan. Kebijakan seperti modul yang menerapkan fungsi pengelolaan tertentu dan terbatas. Kebijakan dirancang agar Anda dapat menambahkan jenis kemampuan pengelolaan umum ke API secara efisien dan andal.
Kebijakan menyediakan fitur seperti keamanan, pembatasan kapasitas, transformasi, dan kemampuan mediasi, sehingga Anda tidak perlu membangun dan memelihara kode sendiri. Anda tidak terbatas pada kumpulan jenis kebijakan yang disediakan oleh Apigee. Anda juga dapat menulis skrip dan kode kustom (seperti aplikasi JavaScript) yang memperluas fungsi proxy API dan memungkinkan Anda berinovasi di atas kemampuan pengelolaan dasar yang didukung oleh kebijakan Apigee.
Buat dan lampirkan kebijakan ke proxy API dan alur bersama menggunakan Apigee di Cloud Code seperti yang dijelaskan di bagian berikut. Bergantung pada jenis kebijakan, Anda mungkin perlu membuat resource, seperti yang dijelaskan dalam Mengelola resource. Lihat juga Mengelola folder dan file di ruang kerja Apigee.
Membuat kebijakan
Untuk membuat kebijakan menggunakan Apigee di Cloud Code:
Di ruang kerja Apigee, lakukan salah satu tindakan berikut berdasarkan tempat Anda ingin melampirkan kebijakan:
Lampirkan ke
Tindakan
Proxy API
Lakukan salah satu tindakan berikut:
Arahkan kursor Anda ke salah satu folder berikut, klik , lalu pilih Buat kebijakan:
Paket proxy apiproxy-name
apiproxy-name/apiproxy
Arahkan kursor ke folder apiproxy-name/apiproxy/policies untuk proxy API, lalu klik .
Alur bersama
Lakukan salah satu tindakan berikut:
Arahkan kursor Anda ke salah satu folder berikut, klik , lalu pilih Buat kebijakan:
sharedflow-name paket alur bersama
sharedflow-name/sharedflowbundle
Arahkan kursor ke folder sharedflow-name/sharedflowbundle/policies untuk alur bersama, lalu klik .
Wizard Buat kebijakan akan terbuka.
Pilih kategori kebijakan yang ingin Anda buat dari daftar.
Untuk mengetahui deskripsi kategori kebijakan, lihat Ringkasan referensi kebijakan.
Masukkan nama unik untuk kebijakan, lalu tekan Enter.
Kebijakan ditambahkan ke folder /policies untuk proxy API atau alur bersama di bagian Apigee dan dibuka di editor.
Edit file sesuai kebutuhan, lalu pilih File > Simpan atau ⌘S untuk menyimpan hasil edit Anda.
Untuk mengetahui informasi selengkapnya tentang cara mengonfigurasi kebijakan, lihat Ringkasan referensi kebijakan.
Buat resource jika diperlukan oleh jenis kebijakan, seperti yang dijelaskan dalam Mengelola resource.
Melampirkan kebijakan ke alur
Kebijakan tidak akan dijalankan hingga dilampirkan ke alur. Anda dapat melampirkan kebijakan ke alur dengan menambahkan elemen <Step> ke elemen alur permintaan atau respons yang sesuai dalam konfigurasi ProxyEndpoint atau TargetEndpoint, seperti yang dijelaskan dalam topik berikut:
Misalnya, konfigurasi berikut melampirkan QuotaPolicy ke <PreFlow> ProxyEndpoint untuk mengonfigurasi jumlah pesan permintaan yang diizinkan oleh proxy API selama jangka waktu tertentu.
[[["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\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```"]]