Tools, FAQ, Tutorials:
'context.Request.MatchedParameters' URL Template Parameters
How to access URL template parameters from "context.Request.MatchedParameters" object in Azure API Policy?
✍: FYIcenter.com
URL template parameters are parameters used in the URL defined in the URL template:
For example, the following URL template contains two template parameters,
"cid", "oid" and "date":
/customers/{cid}/orders/{oid}/?date={date}
When a client system calls this API service operation, it will provide actually values to template parameters. For example:
/customers/101/orders/999/?date=today
Azure API will store template parameters and values in the "context.Request.MatchedParameters" object for you to access. This "context.Request.MatchedParameters" is of the type, "IReadOnlyDictionary".
There are several ways to access template parameters and values:
1. Access it using the array syntax - If you know the parameter name, you access its value using the array syntax. For example:
context.Request.MatchedParameters["parameter_name"] context.Request.MatchedParameters["cid"] context.Request.MatchedParameters["oid"] context.Request.MatchedParameters["date"]
2. Loop through the enumerator with correct type casted - If you don't know the parameter name, you loop through the key value pairs, with each item properly type casted. For example:
IReadOnlyDictionary<string, string> dict context.Request.MatchedParameters foreach (KeyValuePair<string, string> item in dict) { MatchedParameters['"+item.Key+"']: "+item.Value; }
3. Loop through the enumerator with no type casting - If you don't know the parameter name, you loop through the key value pairs with no type casting. This format works better in Azure API management. For example:
var dict context.Request.MatchedParameters foreach (var item in dict) { MatchedParameters['"+item.Key+"']: "+item.Value; }
For more information on the built-in "context" object, see API Management policy expressions Website.
⇒ 'context.Request.Url.Query' Query String Parameters
2018-02-14, 8773👍, 0💬
Popular Posts:
How to create the Hello-3.0.epub package? I have all required files to create Hello-3.0.epub. To cre...
What are "*..." and "**..." Wildcard Parameters in Function Definitions? If you want to define a fun...
Where Can I get a copy of the RSS XML Schema? RSS XML Schema is an XML Schema that defines how an RS...
How to use the Atom Online Validator at w3.org? w3.org feed validation service is provided at http:/...
How to write a policy to set and get custom variables? Here is a policy that sets and gets custom va...