0
votes

I am having difficulty adding text into my url path between my frontend and backend when using Azure Api Management.

I have a Azure functions api with a url like this:

e.g. https://pXXXXX-myapi.azurewebsites.net/api/pXXXXX/alm/{name}

The default api created by Azure API Management is this:

e.g. https://myapi.azure-api.net/pXXXXX/pXXXXX/alm/{name}

Ideally I'd like to Frontend to remove the redundant pXXXXX:

e.g. https://myapi.azure-api.net/pXXXXX/alm/{name}

If I remove it from the front end e.g. GET /pXXXXX/alm/{name} becomes GET /alm/{name}. Then I receive a 500 error. I assume this is because removing "/pXXXXX" removes it from the backend path as well.

So I have tried to use the rewrite-uri policy like so:

<rewrite-uri template="/pXXXXX/alm/{name}" copy-unmatched-params="false" />

I've tried multiple variations of this with no success.

2
Could you clarify how your API is configured now, namely: what's API's URL suffix, web service URL, and if there is any common prefix on every operation URI template. - Vitaliy Kurokhtin

2 Answers

0
votes

Assuming

  • you've changed the frontend for your operation to "GET /alm/{name}"
  • and your backend function app service url is "https://pXXXXX-myapi.azurewebsites.net/api"
  • and your API Base URL is "https://myapi.azure-api.net/pXXXXX"

then rewrite-uri exactly like you pasted is correct. You want to add leading "pXXXXX" to the url. I've reproduced exact same scenario on my side and it works.

500 error does not mean there is something wrong with the path. If you would wrongly configure your url you would get 404. Most probably there is an internal error inside your function app or other policies in the APIM. Just call this API with Ocp-Apim-Trace header set to true and subscription key that allows tracing and you will see what is wrong. Or you can paste trace here if you want so we can help.

0
votes

Posting my own answer but thanks to those who tried to help. I believe the issue came from an error from APIM itself. I assume it was not setting up the policies correctly, because now it is automatically including set-backend-service in the inbound policy whereas it did not over the past 2 days when I have been repeatably re-creating my api.

Now my inbound policy looks like this:

<inbound>
  <base />
  <set-backend-service id="apim-generated-policy" backend-id="pXXXXX-myapi" />
  <rewrite-uri template="/pXXXXX/alm/{name}" copy-unmatched-params="false" />
</inbound>

And my front end api looks as before:

/pXXXXX/alm/{name}