Routing question: I'm trying to support multiple "...
# ktor
r
Routing question: I'm trying to support multiple "functions", each which has some custom resolution code, so I'm putting it in a
route("{...}")
. However some of the functions make use of Ktor routing like
authenticate
. This doesn't play nice with the routes because of ambiguity. If I put the authenticate and the handlers (w/
handle
) in the same route, the authenticate is always taken. If I each handler in it's own
route("{...}")
, the sibling
authenticate
is never taken. And even without that, if I have two of the same authenticates at the same level (one is optional, one isn't), the first is always taken. Is there a way to do something like this, i.e. have routes with fallthrough the request isn't handled? I'm currently using a
RouteSelector
to do this, but it's quite a bit of overhead for something relative (at least conceptually) simple.
I want to have something like:
Copy code
base/
    function1
    function2
    auth1/
        function3
    auth2/
        function4
where I do some resolution in the
function*
handlers and fall through to the others if that resolution fails. I.e. do some custom routing in the
handle
method.
A probably easier to implement alternative is a
Route.route(selector: suspend RoutingResolveContext.(Int) -> RouteSelectorEvaluation, body: Route.() -> Unit)
type method to do simple routing resolution based on a lambda. It's much easier to use than implementing a
RouteSelector
, and much more discoverable. The segment consumption API could probably be streamlined a bit if that's done, but even as is it's much nicer.