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>
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.
The default value shows the expected properties for the object. Those properties are used when defining the resource to deploy.
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.
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.
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"]}")" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With