I have a web api with paths as:
<WebApiHost>/api/v1/operation1
<WebApiHost>/api/v1/operation2
<WebApiHost>/api/v1/operation3
In my Azure API management service, I want the front end to be:
<ApiManagementHost>/api-name/v1/operation1
<ApiManagementHost>/api-name/v1/operation2
<ApiManagementHost>/api-name/v1/operation3
What is the best way to achieve this?
I have tried to achieve this by creating the API in API Management by importing an Open API spec file, and setting the API suffix to “api-name” as well as using a version identifier in the path as “v1”, then gone through each of the operations front-ends and removing the “/api/v1/” sections of the paths that came from the open API definition. Then I have tried adding an inbound policy that applies to all operations such as:
<inbound>
<choose>
<when condition="@(context.Request.OriginalUrl.Path.StartsWith("/test/pmi-quotes/v1/"))">
<rewrite-uri template="/api/v1/@(context.Request.OriginalUrl.Path.Replace("/test/pmi-quotes/v1/", ""))" />
</when>
<otherwise>
<rewrite-uri template="/api/@(context.Request.OriginalUrl.Path)" />
</otherwise>
</choose>
<base />
</inbound>
With the idea being that requests as “/api-name/v1/{operation-path}” get re-written as “/api/v1/{operation-path}”
But this returns a 404. Looking at the trace it seems like the re-write rule isn’t resolving as the URL contains the expression:
forward-request (0.108 ms)
{
"message": "Request is being forwarded to the backend service. Timeout set to 300 seconds",
"request": {
"method": "GET",
"url": "<WebApiHost>/api/v1/@(context.Request.OriginalUrl.Path.Replace("/api-name/v1/", ""))",
"headers": [