azure-api-managementoutbound

How to reuse value from inbound and pass it to outbound Azure APIM


I have a service on Azure APIM have a parameter Token .

the client should provide the token value . and I want to show token value in the response , How it is going to be ?

<policies>
<inbound>
    <base />
</inbound>
<backend>
    <base />
</backend>
<outbound>
    <set-variable name="token" value="@(token)" />
</outbound>
<on-error>
    <base />
</on-error>

Solution

  • I have used the below policy to write the token value in response.

    <outbound>
        <base  />
        <set-variable  name="token"  value="@(context.Request.Headers.GetValueOrDefault("token"))"  />
        <set-body>@("Token: "+ ((string)context.Variables["token"]))</set-body>
    </outbound>
    

    Please make sure to pass the token value in Header.

    enter image description here

    In this way, you can pass the token value in response.