I am trying to figure out Azure’s APIM at the moment and getting nowhere fast.
I have an Azure Function App:
FunctionApp Name: myFunctionApp
FunctionApp Route: /x/y/{z}/get
so the app function url is https://myFunctionApp.azurewebsites.net/api/x/y/{z}/get
i want to use azure apim to use a custom domain primarly to map multiple azure functions apps to be under a single domain for easy of use for web users.
However when the api creates an end point for a function app the endpoint is:
https://my-apim-name.azure-api.net/myFunctionApp/x/y/{z}/get
however the function apps name is in the url, which then create a less friendly and messy endpoint, i would like to be able to remove the function apps name from all api end points
So i want to be able to use:
https://my-apim-name.azure-api.net/x/y/{z}/get
if i use:
<rewrite-uri template="/x/y/{z}/get" />
i get resource not found
2
Answers
Lets say you have an Url
https://xxx.azure-api.net/afreen-fa/Route1
wherein xxx.azure-api.net is host name , afreen-fa is API Url suffix and Route1 is Uri template. So you would like to remove the Url suffix before sending the request to backend which will result in{domainName}/{FunctionAppRoute}
.In order to remove the API Url suffix, you can use the below given policy.
This policy will remove the url suffix.
If you want to pass the value of
FunctionAppRoute
dynamically and remove theFunctionAppName
from the request Url then you the above given policy along with that follow the below steps-I have imported a function app which has route
x/y/{z}/get
and it looks like below-Then I added
<rewrite-uri template="@(context.Request.OriginalUrl.Path.Replace(context.Api.Path, string.Empty))" copy-unmatched-params="true" />
in inbound policy. My function works fine without using this policy too.Invoking the request.
In essence, you want requests to https://my-apim-name.azure-api.net/x/y/{z}/get to be redirected to https://myFunctionApp.azurewebsites.net/api/x/y/{z}/get.
Why don’t you set up the API as follows?
Then, if you have the Operation Frontend set up like this, it should work as expected – no need to use complex policies: