Azure API 管理:重写 uri 策略在版本化 API 中不起作用



我有一个后端API,比如:

GET https://bk.my.com/api/store/goods

我使用 Azure API 管理作为代理。 这是我的 API 的主要设置 "我的测试 API">

Web Service URL:  https://bk.my.com/
API URL suffix :  
Base URL
https://bk-xxx.azure-api.net

添加API操作,这里是操作设置(前端,我只用这个,其他设置保持默认(

Display Name:   Get all goods
Name        :   get-all-goods
URL         :   GET  /api/store/goods

它有效。

https://bk-xxx.azure-api.net/api/store/goods => https://bk.my.com/api/store/goods

现在我需要为此 API 添加一个新版本。这是后端中的 v2 api。

GET https://bk.my.com/api/v2/store/goods

我使用标头分类创建一个新版本 api 名称"v2">

GET https://bk-xxx.azure-api.net/[operation]
api-version: v2

所以在"我的测试 API"中,有 2 个版本

>My Test API       <operation>         <frontend>            <inbound>
Original    ->  get-all-goods -> GET /api/store/goods
v2          ->  get-all-goods -> GET /api/store/goods    <inbound>
<base />
<rewrite-uri template="/api/v2/store/goods" />
</inbound>

当我测试 v2 API 但它不起作用时,跟踪说:

configuration (0 ms)
{
"message": "Unable to identify Api or Operation for this request. Responding to the caller with 404 Resource Not Found."
}

然后我尝试通过删除重写 uri 来修复 v2 api 操作

>My Test API       <operation>         <frontend>            <inbound>
Original    ->  get-all-goods -> GET /api/store/goods
v2          ->  get-all-goods -> GET /api/v2/store/goods     

它现在有效。

所以我的问题是为什么重写 uri 不起作用?

我不知道我是否理解你的问题,但你想用这个重写 -url " 做什么? 是否要将 api 请求发送到此 url?我的意思是,这是你的后端网址吗?

如果是这样,则可以使用设置后端策略。

最新更新