3

I'm trying to setup an endpoint on Azure API Management with url parameters that routes to an Azure function.

EG: GET my-api-gateway.azure-api.net.com/product/{productId}

My inbound policies just set the backend and move the template param to a query param.

    <inbound>
        <base />
        <set-query-parameter name="productId" exists-action="override">
            <value>@(context.Request.MatchedParameters["productId"])</value>
        </set-query-parameter>
        <set-backend-service id="apim-generated-policy" backend-id="product-function" />
    </inbound>

However, when I call my-api-gateway.azure-api.net.com/product/123, the /123 also gets passed to the backend function url

https://my-function.azurewebsites.net/api/product-function/123?productId=123

which results in a 404.

Is there someway to make this work?

2 Answers 2

2

One way to resolve is to add route to the backend as you have shown in your own answer. However, if you cannot do that, then answer to your original question is to introduce a uri rewrite:

<inbound>
    <base />
    <rewrite-uri template="/product-function" copy-unmatched-params="false" />
    <set-query-parameter name="productId" exists-action="override">
        <value>@(context.Request.MatchedParameters["productId"])</value>
    </set-query-parameter>
    <set-backend-service id="apim-generated-policy" backend-id="product-function" />
</inbound>
Sign up to request clarification or add additional context in comments.

Comments

1

The issue was that I also needed to setup routes my the function itself.

In my function.json, I added the following to match my API and now it works:

 "route": "product-function/{productId?}"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.