I’m having trouble with AWS API Gateway’s handling of query parameters. It’s changing the encoding before sending requests to my HTTP backend. This is causing issues because it’s turning %20 into + instead of a space.
Here’s a snippet from my OpenAPI spec:
requestParameters:
integration.request.querystring.myParam: method.request.querystring.myParam
Does anyone know how to:
- Stop API Gateway from messing with the query parameter encoding?
- Make sure my backend gets the original query parameter values without switching to a body-based approach?
I really need the backend to receive the exact characters that were originally encoded. Any ideas on how to fix this?
hey there, have u tried using a lambda function as a proxy? it can intercept the request and fix the encoding before it hits ur backend. might be a bit more work, but it gives u more control over how the params are handled. just a thought!
I’ve encountered this issue before, and it can be quite frustrating.
Unfortunately, API Gateway does tend to modify query parameter encoding by default. One workaround I’ve found effective is to use a custom Lambda authorizer or a Lambda proxy integration. With this approach, you can intercept the request before it reaches your backend and manually re-encode the parameters to match the original format.
Another option is to base64 encode your query parameters on the client side before sending them to API Gateway, then decode them in your backend. This ensures the values remain intact throughout the request lifecycle.
If these solutions aren’t feasible for your use case, you might want to consider using AWS AppSync or directly exposing your backend through an Application Load Balancer instead of API Gateway. These alternatives often provide more flexibility in handling query parameter encoding.
hmm, interesting problem! have you considered using url-safe base64 encoding for your query params? it might help preserve the original values. also, curious about your backend setup - what kind of server are you using? maybe theres a way to tweak its config to handle the encoding differently? let me know if youd like to brainstorm more!