Tools, FAQ, Tutorials:
'context.Request.Url.Query' Query String Parameters
How to access Query String parameters from "context.Request.Url.Query" object in Azure API Policy?
✍: FYIcenter.com
Query String parameters are parameters provided in the query string in the form of
name=value&name=value... format.
For example, the following URL has two query string parameters: "date" and "status"
/customers/101/orders/999/?date=today&status=open
Azure API will store query string parameters and values in the "context.Request.Url.Query" object and "context.Request.OriginalUrl.Query" object for you to access. This "context.Request.Url.Query" is of the type, "IReadOnlyDictionary". But the query string parameter value is of the type, string[], because a single query string parameter can hold multiple values.
There are several ways to access query string 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.Url.Query["parameter_name"][index]
context.Request.Url.Query["date"][0]
context.Request.Url.Query["status"][0]
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[0]+...;
}
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[0]+...;
}
For more information on the built-in "context" object, see API Management policy expressions Website.
⇒ 'context.Request.Body' Request Body
⇐ 'context.Request.MatchedParameters' URL Template Parameters
2024-01-03, ≈18🔥, 1💬
Popular Posts:
How To Read Data from Keyboard (Standard Input) in PHP? If you want to read data from the standard i...
What properties and functions are supported on http.client.HTTPResponse objects? If you get an http....
FYIcenter JSON Validator and Formatter is an online tool that checks for syntax errors of JSON text ...
How to start Docker Daemon, "dockerd", on CentOS systems? If you have installed Docker on your CentO...
What is the Azure AD v1.0 OpenID Metadata Document? Azure AD v1.0 OpenID Metadata Document is an onl...