azure-functionsazure-api-management

How to integrate Azure function in apim policy


I have developed an Azure function and want to integrate it in apim policy using send-request or set-backend-service policy. Can someone please help me achieve this?

I tried the below but I am not getting any result.

<set-backend-service id="apim-generated-policy" base-url="fun.azurewebsites.net/api/httpexample" />
<set-query-parameter name="Content-Type" exists-action="override">
    <value>application/json</value>
</set-query-parameter>
<set-query-parameter name="x-functions-key" exists-action="override">
    <value>xyz</value>
</set-query-parameter>

Solution

  • You don't need to integrate it using policy instead you can import it directly using Azure resource tile.

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    In this way, you can integrate function app with APIM and can test it using test console.

    enter image description here

    If you still want to integrate using policy then you can do so by using below given policy

    <policies>
        <inbound>
            <base />
            <set-backend-service base-url="https://****.azurewebsites.net/api/HttpTrigger1" />
            <set-header name="Content-Type" exists-action="override">
                <value>application/json</value>
            </set-header>
            <set-header name="x-functions-key" exists-action="override">
                <value>lx2****BlEPQ==</value>
            </set-header>
        </inbound>
    </policies>
    

    If you get any error while executing this policy, then you can check the detailed error message in Trace.