Skip to content

Commit 480c3bc

Browse files
authored
Merge pull request #299788 from v-albemi/policy-fragments
Freshness Edit: Azure API Management
2 parents 128b684 + a31bde6 commit 480c3bc

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed
Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
---
2-
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.
44
services: api-management
55
author: dlepow
66

77
ms.service: azure-api-management
88
ms.topic: how-to
9-
ms.date: 04/28/2022
9+
ms.date: 05/15/2025
1010
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.
1113
---
1214

1315
# Reuse policy configurations in your API Management policy definitions
1416

1517
[!INCLUDE [api-management-availability-all-tiers](../../includes/api-management-availability-all-tiers.md)]
1618

17-
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.
1820

1921
Policy fragments help you configure policies consistently and maintain policy definitions without needing to repeat or retype XML code.
2022

2123
A policy fragment:
2224

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.
2628

2729
Limitations:
2830

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.
3032
* Currently, a policy fragment can't nest another policy fragment.
3133
* The maximum size of a policy fragment is 32 KB.
3234

@@ -37,19 +39,20 @@ If you don't already have an API Management instance and a backend API, see:
3739
- [Create an Azure API Management instance](get-started-create-service-instance.md)
3840
- [Import and publish an API](import-and-publish.md)
3941

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.
4143

4244
[!INCLUDE [api-management-navigate-to-instance.md](../../includes/api-management-navigate-to-instance.md)]
4345

4446
## Create a policy fragment
4547

46-
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.
4850

4951
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.
5152

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.":::
5356

5457
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).
5558

@@ -66,10 +69,10 @@ While not required, you may want to [configure](set-edit-policies.md) one or mor
6669

6770
## Include a fragment in a policy definition
6871

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).
7073

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.
7376

7477
For example, insert the policy fragment named *ForwardContext* in the inbound policy section:
7578

@@ -87,27 +90,27 @@ For example, insert the policy fragment named *ForwardContext* in the inbound po
8790
8891
## Manage policy fragments
8992

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.
9194

92-
**To view properties of a policy fragment:**
95+
**To view the properties of a policy fragment:**
9396

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.
9598
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.
97100

98101
**To edit a policy fragment:**
99102

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**.
103106

104107
> [!NOTE]
105-
> Update affects all policy definitions where the fragment is included.
108+
> Updates affect all policy definitions in which the fragment is included.
106109
107110
**To delete a policy fragment:**
108111

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.
111114
1. After all references are removed, select **Delete**.
112115

113116
[!INCLUDE [api-management-policy-ref-next-steps](../../includes/api-management-policy-ref-next-steps.md)]

0 commit comments

Comments
 (0)