Tools, FAQ, Tutorials:
'@{...}' Expression Blocks in Azure API Policy
How to use the "@{...}" expression block in Azure API Policy?
✍: FYIcenter.com
The "@{...}" expression block in Azure API Policy can be used
to include a C# statement block as the attribute value or text value in most policy statements.
C# statement block in the "@{...}" expression block must end with a "return" statement.
When a "@{...}" expression block is included in a policy statement, the C# statement block will be executed first and the returned value of the "return" statement will be used in the policy statement.
For example, the following "set-body" outbound policy statement uses a "@{...}" expression block to remove a number of properties from response body:
<set-body>@{ var response = context.Response.Body.As<JObject>(); foreach (var key in new [] {"minutely", "hourly", "daily"}) { response.Property(key).Remove(); } return response.ToString(); } </set-body>
Note that the C# statements inside "@{...}" must be XML friendly. For example, the "<" character should be replaced with <:
<trace source="MyDebug">@{context.Response.Body.As<JObject>().ToString()}</trace>
Also note that the "@{...}" expression block can not be mixed with text as attribute values or text contents. The following examples are wrong uses of "@(...)" expressions:
<set-variable name="message" value="Hello @{return "world!";}" /> <trace source="MyDebug">Hello @{return "world!";}</trace> <trace source="MyDebug">@{return "Hello";} world!</trace>
For more information on "@{...}" expression blocks, see API Management policy expressions Website.
⇒ Using the 'context' Object in Policy Expressions
2018-02-14, 2728🔥, 0💬
Popular Posts:
How to install "C++/CLI Support" component in Visual Studio? I need to build my Visual Studio C++/CL...
What is EPUB 2.0 Metadata "dc:publisher" and "dc:rights" elements? EPUB 2.0 Metadata "dc:publisher" ...
How To Get the Minimum or Maximum Value of an Array in PHP? If you want to get the minimum or maximu...
Where to find EPUB Sample Files? Here is a list of EPUB sample files collected by FYIcenter.com team...
Can Multiple Paragraphs Be Included in a List Item? Yes. You can include multiple paragraphs in a si...