Skip to content

Commit cf31a1a

Browse files
authored
Merge pull request #299624 from v-albemi/apim-policies
Freshness Edit: Azure API Management
2 parents 7a385d0 + 7922df8 commit cf31a1a

File tree

69 files changed

+105
-100
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+105
-100
lines changed

articles/api-management/api-management-howto-policies.md

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
---
22
title: Policies in Azure API Management
3-
description: Introduction to API Management policies, which change API behavior through configuration. Policy statements run sequentially on an API request or response.
3+
description: Learn about API Management policies, which change API behavior through configuration. Policy statements run sequentially on an API request or response.
44
services: api-management
55
author: dlepow
66

77
ms.service: azure-api-management
88
ms.topic: concept-article
9-
ms.date: 10/18/2023
9+
ms.date: 05/13/2025
1010
ms.author: danlep
1111

12+
#customer intent: As an API publisher, I want to learn about API Management policies so that I can use them to change API behavior.
13+
1214
---
15+
1316
# Policies in Azure API Management
1417

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

17-
In Azure API Management, API publishers can change API behavior through configuration using *policies*. Policies are a collection of statements that are run sequentially on the request or response of an API. API Management provides more than 50 policies out of the box that you can configure to address common API scenarios such as authentication, rate limiting, caching, and transformation of requests or responses. For a complete list, see [API Management policy reference](api-management-policies.md).
20+
In Azure API Management, API publishers can change API behavior through configuration by using *policies*. This article describes how to use policies.
21+
22+
Policies are a collection of statements that are run sequentially on the request or response of an API. API Management provides more than 75 policies out of the box that you can configure to address common API scenarios like authentication, rate limiting, caching, and transformation of requests or responses. For a complete list, see [API Management policy reference](api-management-policies.md).
1823

1924
Popular policies include:
2025

21-
* Format conversion from XML to JSON
22-
* Call rate limiting to restrict the number of incoming calls from a developer
23-
* Filtering requests that come from certain IP addresses
26+
* Format conversion from XML to JSON.
27+
* Call rate limiting to restrict the number of incoming calls from a developer.
28+
* Filtering of requests that come from certain IP addresses.
2429

2530

26-
Policies are applied inside the gateway between the API consumer and the managed API. While the gateway receives requests and forwards them, unaltered, to the underlying API, a policy can apply changes to both the inbound request and outbound response.
31+
Policies are applied inside the gateway between the API consumer and the managed API. Although the gateway receives requests and forwards them, unaltered, to the underlying API, a policy can apply changes to both the inbound request and the outbound response.
2732

28-
## <a name="sections"> </a>Understanding policy configuration
33+
## Understanding policy configuration
2934

3035
Policy definitions are simple XML documents that describe a sequence of statements to apply to requests and responses. To help you configure policy definitions, the portal provides these options:
3136

@@ -34,7 +39,7 @@ Policy definitions are simple XML documents that describe a sequence of statemen
3439

3540
For more information about configuring policies, see [Set or edit policies](set-edit-policies.md).
3641

37-
The policy XML configuration is divided into `inbound`, `backend`, `outbound`, and `on-error` sections. This series of specified policy statements is executed in order for a request and a response.
42+
The policy XML configuration is divided into `inbound`, `backend`, `outbound`, and `on-error` sections. This series of specified policy statements runs in order for a request and a response. Here's what it looks like:
3843

3944
```xml
4045
<policies>
@@ -49,7 +54,7 @@ The policy XML configuration is divided into `inbound`, `backend`, `outbound`, a
4954
<!-- statements to be applied to the response go here -->
5055
</outbound>
5156
<on-error>
52-
<!-- statements to be applied if there is an error condition go here -->
57+
<!-- statements to be applied if there's an error condition go here -->
5358
</on-error>
5459
</policies>
5560
```
@@ -63,42 +68,42 @@ If an error occurs during the processing of a request:
6368
* Execution jumps to the statements in the `on-error` section.
6469

6570
By placing policy statements in the `on-error` section, you can:
66-
* Review the error using the `context.LastError` property.
67-
* Inspect and customize the error response using the `set-body` policy.
71+
* Review the error by using the `context.LastError` property.
72+
* Inspect and customize the error response by using the `set-body` policy.
6873
* Configure what happens if an error occurs.
6974

7075
For more information, see [Error handling in API Management policies](./api-management-error-handling-policies.md).
7176

7277
## Policy expressions
7378

74-
Unless the policy specifies otherwise, [policy expressions](api-management-policy-expressions.md) can be used as attribute values or text values in any of the API Management policies. A policy expression is either:
79+
Unless the policy specifies otherwise, [policy expressions](api-management-policy-expressions.md) can be used as attribute values or text values in any of the API Management policies. A policy expression is one of the following:
7580

76-
* a single C# statement enclosed in `@(expression)`, or
77-
* a multi-statement C# code block, enclosed in `@{expression}`, that returns a value
81+
* A single C# statement enclosed in `@(expression)`
82+
* A multi-statement C# code block, enclosed in `@{expression}`, that returns a value
7883

7984
Each expression has access to the implicitly provided `context` variable and an allowed subset of .NET Framework types.
8085

8186
Policy expressions provide a sophisticated means to control traffic and modify API behavior without requiring you to write specialized code or modify backend services. Some policies are based on policy expressions, such as [Control flow][Control flow] and [Set variable][Set variable].
8287

8388
## Scopes
8489

85-
API Management allows you to define policies at the following *scopes*, from most broad to most narrow:
90+
API Management enables you to define policies at the following scopes, presented here from broadest to narrowest:
8691

8792
* Global (all APIs)
8893
* Workspace (all APIs associated with a selected workspace)
8994
* Product (all APIs associated with a selected product)
9095
* API (all operations in an API)
91-
* Operation (single operation in an API)
96+
* Operation (a single operation in an API)
9297

9398
When configuring a policy, you must first select the scope at which the policy applies.
9499

95-
:::image type="content" source="media/api-management-howto-policies/policy-scopes.png" alt-text="Policy scopes":::
100+
:::image type="content" source="media/api-management-howto-policies/policy-scopes.png" alt-text="Diagram that illustrates the five policy scopes." lightbox="media/api-management-howto-policies/policy-scopes.png":::
96101

97102
### Things to know
98103

99-
* For fine-grained control for different API consumers, you can configure policy definitions at more than one scope
100-
* Not all policies are supported at each scope and policy section
101-
* When configuring policy definitions at more than one scope, you control policy inheritance and the policy evaluation order in each policy section by placement of the `base` element
104+
* For fine-grained control for different API consumers, you can configure policy definitions at more than one scope.
105+
* Not all policies are supported at each scope and policy section.
106+
* When configuring policy definitions at more than one scope, you control policy inheritance and the policy evaluation order in each policy section by placement of the `base` element.
102107
* Policies applied to API requests are also affected by the request context, including the presence or absence of a subscription key used in the request, the API or product scope of the subscription key, and whether the API or product requires a subscription.
103108

104109
[!INCLUDE [api-management-product-policy-alert](../../includes/api-management-product-policy-alert.md)]
@@ -110,11 +115,11 @@ For more information, see:
110115

111116
### GraphQL resolver policies
112117

113-
In API Management, a [GraphQL resolver](configure-graphql-resolver.md) is configured using policies scoped to a specific operation type and field in a [GraphQL schema](graphql-apis-overview.md#resolvers).
118+
In API Management, a [GraphQL resolver](configure-graphql-resolver.md) is configured with policies scoped to a specific operation type and field in a [GraphQL schema](graphql-apis-overview.md#resolvers).
114119

115-
* Currently, API Management supports GraphQL resolvers that specify either HTTP API, Cosmos DB, or Azure SQL data sources. For example, configure a single [`http-data-source`](http-data-source-policy.md) policy with elements to specify a request to (and optionally response from) an HTTP data source.
116-
* You can't include a resolver policy in policy definitions at other scopes such as API, product, or all APIs. It also doesn't inherit policies configured at other scopes.
117-
* The gateway evaluates a resolver-scoped policy *after* any configured `inbound` and `backend` policies in the policy execution pipeline.
120+
* Currently, API Management supports GraphQL resolvers that specify either HTTP API, Azure Cosmos DB, or Azure SQL data sources. For example, you can configure a single [`http-data-source`](http-data-source-policy.md) policy with elements to specify a request to (and optionally response from) an HTTP data source.
121+
* You can't include a resolver policy in policy definitions at other scopes, such as API, product, or all APIs. The policy also doesn't inherit policies configured at other scopes.
122+
* The gateway evaluates a resolver-scoped policy after any configured `inbound` and `backend` policies in the policy execution pipeline.
118123

119124
For more information, see [Configure a GraphQL resolver](configure-graphql-resolver.md).
120125

@@ -138,16 +143,16 @@ Example policy definition at API scope:
138143
</policies>
139144
```
140145

141-
In the example policy definition above:
142-
* The `cross-domain` statement would execute first.
143-
* The [`find-and-replace` policy](find-and-replace-policy.md) would execute after any policies at a broader scope.
146+
In the preceding example policy definition:
147+
* The `cross-domain` statement runs first.
148+
* The [`find-and-replace` policy](find-and-replace-policy.md) runs after any policies at a broader scope.
144149

145150
>[!NOTE]
146-
> If you remove the `base` element at the API scope, only policies configured at the API scope will be applied. Neither product nor global scope policies would be applied.
151+
> If you remove the `base` element at the API scope, only policies configured at the API scope will be applied. Policies configured at product and broader scopes won't be applied.
147152
148153
### Use policy expressions to modify requests
149154

150-
The following example uses [policy expressions][Policy expressions] and the [`set-header`](set-header-policy.md) policy to add user data to the incoming request. The added header includes the user ID associated with the subscription key in the request, and the region where the gateway processing the request is hosted.
155+
The following example uses [policy expressions][Policy expressions] and the [`set-header`](set-header-policy.md) policy to add user data to incoming requests. The added header includes the user ID that's associated with the subscription key in the request, and the region where the gateway processing the request is hosted.
151156

152157
```xml
153158
<policies>

articles/api-management/authentication-basic-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Use the `authentication-basic` policy to authenticate with a backend service usi
3838

3939
## Usage
4040

41-
- [**Policy sections:**](./api-management-howto-policies.md#sections) inbound
41+
- [**Policy sections:**](./api-management-howto-policies.md#understanding-policy-configuration) inbound
4242
- [**Policy scopes:**](./api-management-howto-policies.md#scopes) global, workspace, product, API, operation
4343
- [**Gateways:**](api-management-gateways-overview.md) classic, v2, consumption, self-hosted, workspace
4444

articles/api-management/authentication-certificate-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ms.author: danlep
4141

4242
## Usage
4343

44-
- [**Policy sections:**](./api-management-howto-policies.md#sections) inbound
44+
- [**Policy sections:**](./api-management-howto-policies.md#understanding-policy-configuration) inbound
4545
- [**Policy scopes:**](./api-management-howto-policies.md#scopes) global, workspace, product, API, operation
4646
- [**Gateways:**](api-management-gateways-overview.md) classic, v2, consumption, self-hosted, workspace
4747

articles/api-management/authentication-managed-identity-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Both system-assigned identity and any of the multiple user-assigned identities c
3838

3939
## Usage
4040

41-
- [**Policy sections:**](./api-management-howto-policies.md#sections) inbound
41+
- [**Policy sections:**](./api-management-howto-policies.md#understanding-policy-configuration) inbound
4242
- [**Policy scopes:**](./api-management-howto-policies.md#scopes) global, product, API, operation
4343
- [**Gateways:**](api-management-gateways-overview.md) classic, v2, consumption, self-hosted
4444

articles/api-management/azure-openai-emit-token-metric-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ The `azure-openai-emit-token-metric` policy sends custom metrics to Application
6969

7070
## Usage
7171

72-
- [**Policy sections:**](./api-management-howto-policies.md#sections) inbound
72+
- [**Policy sections:**](./api-management-howto-policies.md#understanding-policy-configuration) inbound
7373
- [**Policy scopes:**](./api-management-howto-policies.md#scopes) global, workspace, product, API, operation
7474
- [**Gateways:**](api-management-gateways-overview.md) classic, v2, consumption, self-hosted, workspace
7575

articles/api-management/azure-openai-semantic-cache-lookup-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Use the `azure-openai-semantic-cache-lookup` policy to perform cache lookup of r
6060
## Usage
6161

6262

63-
- [**Policy sections:**](./api-management-howto-policies.md#sections) inbound
63+
- [**Policy sections:**](./api-management-howto-policies.md#understanding-policy-configuration) inbound
6464
- [**Policy scopes:**](./api-management-howto-policies.md#scopes) global, product, API, operation
6565
- [**Gateways:**](api-management-gateways-overview.md) classic, v2, consumption
6666

articles/api-management/azure-openai-semantic-cache-store-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ The `azure-openai-semantic-cache-store` policy caches responses to Azure OpenAI
4444

4545
## Usage
4646

47-
- [**Policy sections:**](./api-management-howto-policies.md#sections) outbound
47+
- [**Policy sections:**](./api-management-howto-policies.md#understanding-policy-configuration) outbound
4848
- [**Policy scopes:**](./api-management-howto-policies.md#scopes) global, product, API, operation
4949
- [**Gateways:**](api-management-gateways-overview.md) classic, v2, consumption
5050

articles/api-management/azure-openai-token-limit-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ By relying on token usage metrics returned from the OpenAI endpoint, the policy
6262

6363
## Usage
6464

65-
- [**Policy sections:**](./api-management-howto-policies.md#sections) inbound
65+
- [**Policy sections:**](./api-management-howto-policies.md#understanding-policy-configuration) inbound
6666
- [**Policy scopes:**](./api-management-howto-policies.md#scopes) global, workspace, product, API, operation
6767
- [**Gateways:**](api-management-gateways-overview.md) classic, v2, self-hosted, workspace
6868

articles/api-management/cache-lookup-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Use the `cache-lookup` policy to perform cache lookup and return a valid cached
6464
## Usage
6565

6666

67-
- [**Policy sections:**](./api-management-howto-policies.md#sections) inbound
67+
- [**Policy sections:**](./api-management-howto-policies.md#understanding-policy-configuration) inbound
6868
- [**Policy scopes:**](./api-management-howto-policies.md#scopes) global, workspace, product, API, operation
6969
- [**Gateways:**](api-management-gateways-overview.md) classic, v2, consumption, self-hosted, workspace
7070

articles/api-management/cache-lookup-value-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Use the `cache-lookup-value` policy to perform cache lookup by key and return a
4545

4646
## Usage
4747

48-
- [**Policy sections:**](./api-management-howto-policies.md#sections) inbound, outbound, backend, on-error
48+
- [**Policy sections:**](./api-management-howto-policies.md#understanding-policy-configuration) inbound, outbound, backend, on-error
4949
- [**Policy scopes:**](./api-management-howto-policies.md#scopes) global, workspace, product, API, operation
5050
- [**Gateways:**](api-management-gateways-overview.md) classic, v2, consumption, self-hosted, workspace
5151

0 commit comments

Comments
 (0)