簡體   English   中英

map api如何在azure api管理中動態請求

[英]How to map api request dynamically in azure api management

我想設置 api 管理網關,它使用 url 中的路徑重定向到某個后端 url。我應該使用哪個策略?

請求就像-

等等....

它轉發到一些后端,例如-

等等....

基本上我想將 uri 路徑 (/api/v1/getA) 傳遞給請求中的后端。

主要要求是-我有多個請求路徑,並希望在后端動態地對它們進行 map。

我正在嘗試使用

<policies>
    <inbound>
        <set-backend-service base-url="http://example.org/" />
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>```

更新問題的更新:

不可能根據路徑進行動態路由。

  1. 獲取https://something.azure-api.net/api/v1/getA
  2. 獲取https://something.azure-api.net/api/v1/getB/C
  3. 獲取https://something.azure-api.net/api/v1/putD
  4. 發布 https://something.azure-api.net/api/v1/putD

所有 4 個案例都是 API 管理中的 4 個不同操作。


以前的回答

根據你的描述你有

一個 API 稱為api有兩個版本
v1v2

在此處輸入圖像描述

請使用rewrite-uri策略添加路徑。
例子:

<rewrite-uri template="/v2/US/hardware/{storenumber}&{ordernumber}?City=city&State=state" />

API api版本v1有一個操作:
**.azure-api.net/api/v1/getA

要將請求轉發到http://example.org/api/v1/getA ,需要以下策略:

<policies>
    <inbound>
        <base />
        <set-backend-service base-url="http://example.org/" />
        <rewrite-uri template="getA" copy-unmatched-params="true" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

在此處輸入圖像描述

v2版本的 API api有一項操作:

**.azure-api.net/api/v2/getB/C

要將請求轉發到http://example.org/api/v2/getB/C ,需要以下策略:

<policies>
    <inbound>
        <base />
        <set-backend-service base-url="http://example.org/" />
        <rewrite-uri template="getB/C" copy-unmatched-params="true" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM