Serverless offline auto decodes path parameters where as AWS doesn't. (AWS does auto decode query params though)
E.g. you have an endpoint like "/blogposts/{id}" and an id of "test%7Cid".
In AWS event.pathParameters.id is "test%7Cid" and in serverless offline its "test|id"
@electrikdevelopment Thanks for reporting this. Could you work a fix please ? Thanks
v3.15.2, ty @electrikdevelopment
It seems API Gateway auto decodes path parameters now.
Request to "/users/{id}" and an id of "us-east-1:af33425f":
@fwang What do you see if you use 'us-east-1%3Aaf33425f' ? Some clients / browsers don't encode all characters that the url spec says they should. It theory ':' should be encoded by the client. (chrome doesn't for me)
I'm still seeing API Gateway leave path params the same as the client sent. Ideally the solution in offline would be to match that behaviour exactly. Someone raised this before but I couldn't see a reasonable way to do that with the libraries in use (open to suggestions ;) ). The current solution decodes and re-encodes them hence the discrepancy.
In the absence of the ideal solution IMO its better for offline to reencode them. From an api point of view in the real world, depending on the client both ':' or '%3A' could be present in the path param so there is a need for the lambda to handle both cases. Perviously when offline auto decoded them it was possible to write something that worked on offline but then did or didn't in AWS depending on the client used to make the request.
Hope that makes sense :)
@electrikdevelopment Thanks for the quick reply. That makes sense.
I observed the same behaviour on Chrome, Safari and Firefox (on OSX). If I change the request to "/users/us-east-1%3Aaf33425f", both AWS and offline shows "us-east-1%3Aaf33425f".
Another observation:
requesting to "/users/us-east-1%3Aaf33425f" in offline, the console shows this (2nd line is from console.log of id)
Serverless: GET /users/us-east-1:af33425f (位: user_get)
us-east-1%3Aaf33425f
It seems the browser decoded it, and offline encoded back again?
Most helpful comment
It seems API Gateway auto decodes path parameters now.
Request to "/users/{id}" and an id of "us-east-1:af33425f":