Home > Back-end >  set backend url after extracting it from header azure apim
set backend url after extracting it from header azure apim

Time:05-10

Hi I am trying to implement such a functionality where i need to make sure that the api is going through gateway so have created a apim and i need to extract header from the call and route to that call : so far i have done this policy:

<policies>
    <inbound>
        <set-variable name="host" value="@(context.Request.Headers.GetValueOrDefault("uri","http://google.com/"))" />
        <set-backend-service base-url="${{ variables.host}}" />
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

but its giving error :

Error in element 'set-backend-service' on line 16, column 4: Value is not a valid absolute URL.

CodePudding user response:

To resolve this issue, there are two things to do:

  1. Define the parameter type you are using in the template file.

  2. When defining param's you need to signify the start and end of the command using square brackets.

Try this:

<set-backend-service base-url=\"[parameters('backend_url')]\"/>

Refer this document to know about parameters in ARM templates.

CodePudding user response:

<set-backend-service base-url="@((string)context.Variables["host"])" />
  • Related