dbartholomae / lambda-middleware

A collection of middleware for AWS lambda functions.
https://dbartholomae.github.io/lambda-middleware/
MIT License
151 stars 18 forks source link

Interest in a path parser middleware? #48

Closed parkan closed 3 years ago

parkan commented 3 years ago

Is your feature request related to a problem? Please describe. Certain lambda function hosts (netlify functions in particular) do not provide a path parser/do not populate pathParameters, nor offer a way to pack path params into query params using rewrites. I wrote a very simple path parser middleware that addresses this.

Would you be willing to help with a PR?

Describe the solution you'd like

The code is very simple, most of it is here: https://gist.github.com/parkan/f0b95f343e18aaadd1bb93b4ca67806d

I'm using this in production (ish), only thing I see being needed is e2e tests.

Describe alternatives you've considered

The netlify dev (local testing) env provides packing of path params into query params, however this doesn't work in production. The only other alternative is manually unpacking them in the handler.

Additional context

The downside here is that the handler wrapper needs to know the path expression to parse out the params, but I don't see a way to work around it, aside from parsing _redirects at build time.

parkan commented 3 years ago

one thing that can happen is parametrizing this to offer url encode handling similar to https://www.npmjs.com/package/@middy/http-urlencode-path-parser, but I think that's a v1.1 feature

dbartholomae commented 3 years ago

Sounds good! If you want to create your own, compatible repo, I can link it. I would also be open to a PR, but then would need a high level of test coverage (see existing examples). In the second case, I'm also happy to help with this in case you run into any trouble :) For me, the non-dynamic nature of path parsing would actually be an advantage: in a 1.1 it could include explicit validation similar to class-validator, to tighten the type of the path parameter object.

github-actions[bot] commented 3 years ago

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.