Configure request per prefix


let’s say that my applications handles three main prefixes:

/web - routes accessible via browser, session authentication
/json - like above but json responses
/api - REST api routes.

is it possible to configure the request object differently depends on the route prefix? I’m looking for solution similar to the laravel’s when you can attach special behaviour to the route.

I know I can configure many things in controller (like cors) but I would like to avoid it. For example calling /api/customers and /json/customers should return exactly same results but the first should have cors, csrf, session authentication and second only bearer.

Best regards,