Soru

Zorluk: OrtaDefine API Management Policies

You are configuring an inbound policy for an Azure API Management (APIM) instance. You need to route incoming API requests to a specific regional backend API based on the value of a custom header named `X-Region`. If the header value is `EU`, the request must be routed to `https://eu-backend.contoso.com/api`. Otherwise, the request must use the default backend. What are the correct API Management policy element names required to complete the XML configuration below?

Cevap:xml
<inbound>
<base />
<choose>
<【when】 condition="@(context.Request.Headers.GetValueOrDefault("X-Region") == "EU")">
<【set-backend-service】 base-url="https://eu-backend.contoso.com/api" />
</【when】>
</choose>
</inbound>

Cevap

The correct policy elements are 'when' to evaluate the conditional routing expression and 'set-backend-service' to redirect the backend API base URL.
The correct elements are 'when' and 'set-backend-service'. The `<when>` element defines a conditional branch inside the `<choose>` parent element. The `<set-backend-service>` element alters the destination endpoint for the incoming API request during the inbound processing pipeline.

Adım Adım Çözüm

1
Identify the conditional block element within the `<choose>` policy structure.
The `<choose>` element executes policies in the first nested `<when>` element whose condition evaluates to true.
To evaluate whether the custom header `X-Region` is equal to `EU`, a conditional `<when>` block must be declared.
2
Identify the policy element required to alter the destination URL for the backend API.
The `<set-backend-service>` policy dynamically changes the destination backend base URL for the request.
To route requests to the regional URL when the condition is met, the `<set-backend-service>` policy with the `base-url` attribute must be placed inside the conditional block.

Anahtar Kavram

Configuring conditional routing policies in Azure API Management using the choose-when policy structure and the set-backend-service policy element.
Tahmini Süre:1m 30s
Bu soruyu puanla