Hi,
I want to send a queryparam in the request which will work as case insensitive parameter, and I can use its value in some assign message policy.
I tried with all upper and all lower, but I need any letter in any case to work.
I don’t want to manually put all scenarios.
Any help is appreciated. Thanks in advance.
1 Like
..which will work as case insensitive parameter,
Not clear.
Do you men to say that you want the value of the parameter to be treated case-insensitively? Eg foo?q=bar is the same as foo?q=BAR. ?
Or do you mean that you want the name of the parameter will be treated case-insensitively. Eg foo?q=bar is the same as foo?Q=bar ?
The former is easy with a {toUpperCase(request.queryparam.q)} in a message template.
For the latter you must use JavaScript to parse the query params and produce a hash of all lowercased parameters.
You can do it with the help of the URI.js module.
If you use that module, the code would look something like this.
var uri = URI(context.getVariable('request.uri'));
// get data map:
var search = uri.search(true);
// suppose the inbound API request looks like:
// [http://host/basepath/suffix?PARAM1=value1¶m2=value2](http://host/basepath/suffix?PARAM1=value1¶m2=value2)
//
// then, the search object would look like this:
// {
// "PARAM1": "value1",
// "param2": "value2"
// }
var downcasedParams = {};
Object.keys(search).forEach(function (key) {
downcasedParams[key.toLowerCase()] = search[key];
});
// you may need to be careful handling repeated query params.
I was asking for the second one. q and Q. I was asking for any solution other than scripting. I am having a 6 letters word as the query param.
1 Like
I have the same issue here, have you found a way out?
nope, I had to use scripting. Didn’t get any option in availble policies.
1 Like