Question

Difficulty: MediumDefine API Management Policies

A company hosts a legacy REST service behind an Azure API Management (APIM) instance. To prepare the service for migration, you must configure APIM policies to meet the following requirements:
- Remove the '/api/v1' path prefix from all incoming request URLs before forwarding them to the backend service.
- Limit clients to a maximum rate of 500 requests per 60 seconds per subscription.

Which two of the following policy fragments should you add to the <inbound> section of the policy XML file to satisfy these requirements? (Choose two.)

  1. <rewrite-uri template="@(context.Request.Url.Path.Replace("/api/v1", ""))" />Answer
  2. <rate-limit calls="500" renewal-period="60" />Answer
  3. C
    <rate-limit-by-key calls="500" renewal-period="60" counter-key="@(context.Request.IpAddress)" /> placed inside the <outbound> section
  4. D
    <rewrite-uri template="@(context.Request.Url.Path.Replace("/api/v1", ""))" /> placed inside the <on-error> section

Answer

The correct policy fragments are the rewrite-uri policy to modify the request path and the rate-limit policy to limit incoming request rates, both placed in the inbound section.
The rewrite-uri policy and the rate-limit policy are inbound-processing directives. Placing them in the inbound block allows APIM to strip the API version prefix and verify rate limit quotas before routing the request to the backend service.

Step-by-Step Solution

1
Identify the policy required to modify the incoming request path.
The rewrite-uri policy template expression correctly replaces '/api/v1' with an empty string.
Request path modification must happen before routing the request to the backend, placing this policy in the inbound section.
2
Identify the policy required to enforce a rate limit per subscription.
The rate-limit policy allows limiting calls to 500 per 60 seconds.
Rate limiting is an incoming request control policy that must reside in the inbound section to block calls before hitting the backend.
3
Eliminate options placing inbound policies in incorrect execution sections.
Outbound and on-error configurations are discarded.
Outbound policies run after backend execution, and on-error policies run only during execution errors, making them invalid sections for inbound request filtering and URI rewriting.

Key Concept

Azure API Management inbound policy execution and structure
Rate this question