Skip to content

Maintenance: Change path parameter in the Middleware signature #4531

@sdangol

Description

@sdangol

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

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler UtilityinternalPRs that introduce changes in governance, tech debt and chores (linting setup, baseline, etc.)

Type

No type

Projects

Status

Coming soon

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions