Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encoding Query Parameters from API Gateway

I have an created a REST application in nodejs and also I have configured API gateway for the URLs. I have a URL with query parameters. When one request from postman with query params with special characters like +,\ , then I need to encode these from API gateway. Is it possible to do that? Someone please help with an answer... Thanks in advance

like image 921
Krishnachandran E S Avatar asked Jul 14 '26 23:07

Krishnachandran E S


1 Answers

We need to override the query parameter in mapping template of IntegrationRequest, function we need in vtl is $util.urlEncode.

The moment we start overriding, we need to ensure to build entire request body, parameters, etc.

Template from here, i just added one additional function $util.urlEncode call to encode parameters. If query parameter value is Test4! it will be changed to Test4%21

#set($allParams = $input.params())
{
  "params" : {
    #foreach($type in $allParams.keySet())
    #set($params = $allParams.get($type))
    "$type" : {
      #foreach($paramName in $params.keySet())
      "$paramName" : "$util.escapeJavaScript($util.urlEncode($params.get($paramName)))"
      #if($foreach.hasNext),#end
      #end
    }
    #if($foreach.hasNext),#end
    #end
  }
}

enter image description here

like image 134
Balu Vyamajala Avatar answered Jul 17 '26 16:07

Balu Vyamajala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!