Tools, FAQ, Tutorials:
Policy to Set and Get Custom Variables
How to write a policy to set and get custom variables?
✍: FYIcenter.com
Here is a policy that sets and gets custom variables:
<!-- Set-Get-Variable-Policy.xml
Copyright (c) FYIcenter.com
-->
<policies>
<inbound>
<set-variable name="version" value="1.11" />
<set-variable name="method" value="@(context.Request.Method)" />
<set-variable name="message" value="@("Hello world!")" />
<set-variable name="isTrue" value="@(1 < 2)" />
<set-variable name="name" value="@("John & Sons")" />
<set-variable name="entity" value="@("& = &")" />
</inbound>
<backend>
</backend>
<outbound>
<return-response>
<set-status code="200" reason="Ok" />
<set-body>@{
var res = "";
res = res + "version: "+context.Variables["version"]+"\n";
res = res + "method: "+context.Variables["method"]+"\n";
res = res + "message: "+context.Variables["message"]+"\n";
res = res + "isTrue: "+context.Variables["isTrue"]+"\n";
res = res + "name: "+context.Variables["name"]+"\n";
res = res + "entity: "+context.Variables["entity"]+"\n";
return res;
}</set-body>
</return-response>
</outbound>
<on-error>
</on-error>
</policies>
Note that < and & signs can be directly used in @(...) expressions, which seems be to processed before Azure validating the policy as XML document.
Also note that XML entities will be decoded before the @(...) expression gets processed. So entering in < or < in a @(...) expression gives the same result.
⇒ 2017 Version of API Management Services
2017-10-23, ∼3437🔥, 0💬
Popular Posts:
How to use "link" command tool to link objet files? If you have object files previously compiled by ...
How to add images to my EPUB books Images can be added into book content using the XHTML "img" eleme...
How to access Query String parameters from "context.Request.Url.Que ry"object in Azure API Policy? Q...
What is EPUB 2.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 2.0 Metadata "dc:publisher" ...
How to access Request body from "context.Request.Body" object in Azure API Policy? Request body is t...