Soru

Zorluk: ZorDefine API Management Policies

An enterprise is migrating its legacy payment processing API to Azure API Management (APIM). To support blue-green deployments, the API gateway must route incoming requests dynamically based on a custom HTTP header named `X-Routing-Environment`. If the header value is `canary`, the gateway must route the request to a backend service registered with the ID `canary-endpoint`. Otherwise, the request should continue to the default backend.

Complete the following XML policy snippet to implement the dynamic routing logic. Fill in the blanks with the correct context variable and policy element name.

Cevap:Complete the XML policy configuration below to dynamically route requests based on the header value:

xml
<policies>
<inbound>
<base />
<choose>
<when condition="@(【context】.Request.Headers.GetValueOrDefault("X-Routing-Environment") == "canary")">
<【set-backend-service】 backend-id="canary-endpoint" />
</when>
</choose>
</inbound>
</policies>

Cevap

The first blank must be filled with `context` and the second blank must be filled with `set-backend-service`.
The correct configuration uses the read-only C# context variable `context` to access the HTTP headers of the incoming request, and uses the `set-backend-service` policy to override the default backend with the registered backend service ID.

Adım Adım Çözüm

1
Identify the C# context variable used within APIM policy expressions.
The `context` variable provides access to request headers and other contextual data.
The policy expression needs to read the incoming request header collection via `context.Request.Headers`.
2
Identify the policy element that redirects a request to a registered backend ID.
The `<set-backend-service>` policy element allows routing requests to a backend specified by its ID.
The requirement specifies routing the request to a backend service registered with the ID `canary-endpoint`, which is configured using `<set-backend-service backend-id="canary-endpoint" />`.

Anahtar Kavram

Dynamic backend routing using context variables and set-backend-service policies in Azure API Management.
Bu soruyu puanla