Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Work with URL template parameter values in policy templates

In API Management, how do you access URL template parameters through a policy?

In this instance, my operation is called test, the HTML verb is GET, and the URL template is as below -

/test/{variable_name1}/{variable_name2}

I was under the impression that accessing the value of a parameter was as simple as {variable_name1}. However, the example below does not set the variable "rowkey" as expected. Rather it has a value of {variable_name1}-{variable_name2}.

What am I doing wrong here?

<policies>
    <inbound>
        <set-variable name="rowkey" value="{variable_name1}-{variable_name2}" />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <set-header name="Row-Key" exists-action="override">
            <value>@((string)context.Variables["rowkey"])</value>
        </set-header>
    </outbound>
</policies>
like image 344
David Gard Avatar asked Feb 15 '17 16:02

David Gard


People also ask

What is the difference between variables and parameters in an azure arm template?

Parameters will prompt the user for the values unless they are hardcoded. Variables are used to have a single point where information is declared rather than repeating that value all the way through a template.

What is default value in arm template?

The default value shows the expected properties for the object. Those properties are used when defining the resource to deploy.

What is OCP Apim trace?

On the Message tab, the ocp-apim-trace-location header shows the location of the trace data stored in Azure blob storage. If needed, go to this location to retrieve the trace. Trace data can be accessed for up to 24 hours.

What is Apim?

APIM may refer to: API Management (Computer Science); a way to create API (application programming interface) gateways for back-end services using products such as Apigee, Azure API Management, TIBCO Mashery, Mulesoft, WSO2, AWS API Gateway.


1 Answers

You'd have to use expressions to achieve what you want, like:

<set-variable 
   name="rowkey" 
   value="@(context.Request.MatchedParameters["variable_name1"] + "-" + context.Request.MatchedParameters["variable_name2"])" />

or use string interpolation:

<set-variable 
   name="rowkey" 
   value="@($"{context.Request.MatchedParameters["variable_name1"]}-{context.Request.MatchedParameters["variable_name2"]}")" />
like image 190
Vitaliy Kurokhtin Avatar answered Dec 31 '22 14:12

Vitaliy Kurokhtin