[英]How to choose to set back-end using rewrite-uri to two different logic apps in Azure API Management?
[英]Azure API Management Policy(how to do rewrite-uri)
我是 Azure API 管理的新手。 我正在構建一個將更改初始請求 url 的策略。如何從正文中提取insurer_id 並將其傳遞給我的后端。
{
"insurer_name": "Tony",
"insurer_id": "12345",
"comments": "This is test",
}
mybackend.com/api/relationship/approve/{insurer_id}
我知道我必須將 id 提取為 JObject,將其存儲在變量中並執行 rewrite-uri。 但我不確定,我如何在 Azure 政策中實現這一點。 一個小例子會很有幫助。
謝謝
您必須從請求正文中讀取insurer_id
並將其設置為變量。
<set-variable name="insurerId" value="@{
var body = context.Request.Body.As<JObject>(true);
return body["insurer_id"].Value<string>();
}" />
此變量可用於rewrite-uri :
<rewrite-uri template="@("/api/relationship/approve/" + context.Variables.GetValueOrDefault<string>("insurerId") copy-unmatched-params="false" />
完整的政策:
<policies>
<inbound>
<base />
<set-variable name="insurerId" value="@{
var body = context.Request.Body.As<JObject>(true);
return body["insurer_id"].Value<string>();
}" />
<rewrite-uri template="@("/api/relationship/approve/" + context.Variables.GetValueOrDefault<string>("insurerId") copy-unmatched-params="false" />
<set-backend-service base-url="https://mybackend.com" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.