You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Reuse policy configurations in Azure API Management | Microsoft Docs
3
-
description: Learn how to create and manage reusable policy fragments in Azure API Management. Policy fragments are XML elements containing policy configurations that can be included in any policy definition.
2
+
title: Reuse Policy Configurations in API Management | Microsoft Docs
3
+
description: Learn how to create and manage reusable policy fragments, XML snippets that contain policy configurations, in Azure API Management.
4
4
services: api-management
5
5
author: dlepow
6
6
7
7
ms.service: azure-api-management
8
8
ms.topic: how-to
9
-
ms.date: 04/28/2022
9
+
ms.date: 05/15/2025
10
10
ms.author: danlep
11
+
12
+
#customer intent: As an API developer, I want to learn how to create and manage policy fragments so that I can reuse policy configurations.
11
13
---
12
14
13
15
# Reuse policy configurations in your API Management policy definitions
This article shows you how to create and use *policy fragments* in your API Management policy definitions. Policy fragments are centrally managed, reusable XML snippets containing one or more API Management [policy](api-management-howto-policies.md) configurations.
19
+
This article shows how to create and use *policy fragments* in your Azure API Management policy definitions. Policy fragments are centrally managed, reusable XML snippets that contain one or more API Management [policy](api-management-howto-policies.md) configurations.
18
20
19
21
Policy fragments help you configure policies consistently and maintain policy definitions without needing to repeat or retype XML code.
20
22
21
23
A policy fragment:
22
24
23
-
* Must be valid XML containing one or more policy configurations
24
-
*May include [policy expressions](api-management-policy-expressions.md), if a referenced policy supports them
25
-
* Is inserted as-is in a policy definition by using the [include-fragment](include-fragment-policy.md) policy
25
+
* Must be valid XML that contains one or more policy configurations.
26
+
*Can include [policy expressions](api-management-policy-expressions.md), if a referenced policy supports them.
27
+
* Is inserted as-is in a policy definition via the [include-fragment](include-fragment-policy.md) policy.
26
28
27
29
Limitations:
28
30
29
-
* A policy fragment can't include a policy section identifier (`<inbound>`, `<outbound>`, etc.) or the `<base/>` element.
31
+
* A policy fragment can't include a policy section identifier (`<inbound>`, `<outbound>`, for example) or the `<base/>` element.
30
32
* Currently, a policy fragment can't nest another policy fragment.
31
33
* The maximum size of a policy fragment is 32 KB.
32
34
@@ -37,19 +39,20 @@ If you don't already have an API Management instance and a backend API, see:
37
39
-[Create an Azure API Management instance](get-started-create-service-instance.md)
38
40
-[Import and publish an API](import-and-publish.md)
39
41
40
-
While not required, you may want to [configure](set-edit-policies.md) one or more policy definitions. You can copy policy elements from these definitions when creating policy fragments.
42
+
Although it's not required, you might want to [configure](set-edit-policies.md) one or more policy definitions. You can copy policy elements from these definitions when you create policy fragments.
1. In the left navigation of your API Management instance, under **APIs**, select **Policy fragments** >**+ Create**.
47
-
1. In the **Create a new policy fragment** window, enter a **Name** and an optional**Description** of the policy fragment. The name must be unique within your API Management instance.
48
+
1. In the left pane of your API Management instance, under **APIs**, select **Policy fragments**. In the **Policy fragments** pane, select**+ Create**.
49
+
1. In the **Create a new policy fragment** window, enter a **Name** and, optionally, a**Description** of the policy fragment. The name must be unique within your API Management instance.
48
50
49
51
Example name: *ForwardContext*
50
-
1. In the **XML policy fragment** editor, type or paste one or more policy XML elements between the `<fragment>` and `</fragment>` tags.
51
52
52
-
:::image type="content" source="media/policy-fragments/create-fragment.png" alt-text="Screenshot showing the create a new policy fragment form.":::
53
+
1. In the **XML policy fragment** editor, type or paste one or more policy XML elements between the `<fragment>` and `</fragment>` tags:
54
+
55
+
:::image type="content" source="media/policy-fragments/create-fragment.png" alt-text="Screenshot showing the Create a new policy fragment window.":::
53
56
54
57
For example, the following fragment contains a [`set-header`](set-header-policy.md) policy configuration to forward context information to a backend service. This fragment would be included in an inbound policy section. The policy expressions in this example access the built-in [`context` variable](api-management-policy-expressions.md#ContextVariables).
55
58
@@ -66,10 +69,10 @@ While not required, you may want to [configure](set-edit-policies.md) one or mor
66
69
67
70
## Include a fragment in a policy definition
68
71
69
-
Configure the [`include-fragment`](include-fragment-policy.md) policy to insert a policy fragment in a policy definition. For more information about policy definitions, see [Set or edit policies](set-edit-policies.md).
72
+
Use the [`include-fragment`](include-fragment-policy.md) policy to insert a policy fragment in a policy definition. For more information about policy definitions, see [Set or edit policies](set-edit-policies.md).
70
73
71
-
* You may include a fragment at any scope and in any policy section, as long as the underlying policy or policies in the fragment support that usage.
72
-
* You may include multiple policy fragments in a policy definition.
74
+
* You can include a fragment at any scope and in any policy section, as long as the underlying policy or policies in the fragment support the usage.
75
+
* You can include multiple policy fragments in a policy definition.
73
76
74
77
For example, insert the policy fragment named *ForwardContext* in the inbound policy section:
75
78
@@ -87,27 +90,27 @@ For example, insert the policy fragment named *ForwardContext* in the inbound po
87
90
88
91
## Manage policy fragments
89
92
90
-
After creating a policy fragment, you can view and update the properties of a policy fragment, or delete the policy fragment at any time.
93
+
After you create a policy fragment, you can view and update its properties or delete it at any time.
91
94
92
-
**To view properties of a policy fragment:**
95
+
**To view the properties of a policy fragment:**
93
96
94
-
1. In the left navigation of your API Management instance, under **APIs**, select **Policy fragments**. Select the name of your fragment.
97
+
1. In the left pane of your API Management instance, under **APIs**, select **Policy fragments**. Select the name of your fragment.
95
98
1. On the **Overview** page, review the **Policy document references** to see the policy definitions that include the fragment.
96
-
1. On the **Properties** page, review the name and description of the policy fragment. The name can't be changed.
99
+
1. On the **Properties** page, under **Settings**, review the name and description of the policy fragment. The name can't be changed.
97
100
98
101
**To edit a policy fragment:**
99
102
100
-
1. In the left navigation of your API Management instance, under **APIs**, select **Policy fragments**. Select the name of your fragment.
101
-
1.Select**Policy editor**.
102
-
1. Update the statements in the fragment and then select **Apply**.
103
+
1. In the left pane of your API Management instance, under **APIs**, select **Policy fragments**. Select the name of your fragment.
104
+
1.Under **Settings**, select**Policy editor**.
105
+
1. Update the statements in the fragment, and then select **Apply**.
103
106
104
107
> [!NOTE]
105
-
> Update affects all policy definitions where the fragment is included.
108
+
> Updates affect all policy definitions in which the fragment is included.
106
109
107
110
**To delete a policy fragment:**
108
111
109
-
1. In the left navigation of your API Management instance, under **APIs**, select **Policy fragments**. Select the name of your fragment.
110
-
1. Review **Policy document references** for policy definitions that include the fragment. Before a fragment can be deleted, you must remove the fragment references from all policy definitions.
112
+
1. In the left pane of your API Management instance, under **APIs**, select **Policy fragments**. Select the name of your fragment.
113
+
1. Review **Policy document references** for policy definitions that include the fragment. Before you delete a fragment, you must remove the fragment references from all policy definitions.
111
114
1. After all references are removed, select **Delete**.
0 commit comments