In Amazon API gateway I'm using a body mapping template to transform the request. I found that keeping track of the commas was cumbersome (especially with multiple optional parameters) so I came up with the following:
{
"context": { /* context params */ },
"request": {
#foreach($queryParam in $input.params().querystring.keySet())
"$queryParam" : "$input.params().querystring.get($queryParam)"
#if($foreach.hasNext),#end
#end
}
}
The issue I find with this is that when $input.params().querystring.get($queryParam)
is an integer (and shouldn't be enclosed with quotes) then it doesn't work. That seems fair enough, but how do I improve this to check if $input.params().querystring.get($queryParam)
is a string, so that I can subsequently wrap it in quotation marks?
Request
http://www.somewebsite.com/apiendpoint?id=4&name=Terry&aliases=[Tel,Terry]
Transformation
{
"id": "4",
"name": "Terry",
"aliases": "[Tel,Terry]"
}
Expected Transformation
{
"id": 4,
"name": "Terry",
"aliases": ["Tel","Terry"]
}