pmlopes/yoke

Add filter-base middleware selection

ddossot opened this issue · 2 comments

It's currently possible to filter middlewares based on routes: use(route, middleware)

It would be super powerful to be able to do the same with a more generic YokeRequestFilter (with accept(request) -> boolean) like this: use(filter, middleware).

Rationale: being able to use other request properties than path for filtering, like for example the value of the Accept header.

not totally sure about return boolean since if you want to filter you might also want to filter say based on some backend database value (say oauth tokens) then you need to be asynchronous...

On the other end can we just make a middleware a la Router that is instantiated with a filter interface and the just has a method use(Middleware... middlewares) ?

Indeed, creating a middleware that conditionally delegates to another middleware, or list of middlewares, would work too. Thanks for your feedback.