-
Notifications
You must be signed in to change notification settings - Fork 175
Description
Summary
Currently, the Middleware
type for middleware functions describes a function with an object argument with 2 top level keys: params
, reqCtx
, next
.
It could may as well be considered as part of the request context with which we could change the type RequestContext
to add the params
there and just do reqCtx.params
when needed.
This will change the middleware implementation from:
const loggingMiddleware: Middleware = async ({ params, reqCtx, next) => {
logger.info('Path parameters', { params });
await next();
};
to:
const loggingMiddleware: Middleware = async ({ reqCtx, next) => {
logger.info('Path parameters', { params: reqCtx.params });
await next();
};
Similarly, the RouteHandler
type can also be changed to move the args
parameter into the reqCtx
parameter.
This would mean, the route parameter will now be obtained from the handler as follows:
app.get('/todos/:todoId', async (reqCtx) => {
return { actualPath: `/todos/${reqCtx.params.todoId}` };
});
Why is this needed?
The params
key is used for the Route parameters extracted from the URL path. The params
key doesn't seem to be used very often and it could may as well be considered as part of the request context with which we could just do reqCtx.params
when needed.
Which area does this relate to?
Event Handler
Solution
No response
Acknowledgment
- This request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status