How do you get the route of a call in Ktor 3? I'm ...
# ktor
r
How do you get the route of a call in Ktor 3? I'm trying to migrate this code:
Copy code
fun Routing.setupSomeStuff() {
    …
    environment!!.monitor.subscribe(Routing.RoutingCallStarted) { call ->
        …
        call.route.parent?.toString()
        …
    }
    …
}
RoutingCallStarted
just disappeared and I can't find a context where
call.route
is a thing anymore. I don't see this breaking change documented anywhere.
e
Hey, could you replace Routing.RoutingCallStarted with just RoutingCallStarted?
r
This seems to work:
Copy code
application.monitor.subscribe(RoutingRoot.RoutingCallStarted) { call ->
        call.route.parent?.toString()
    }
So
Routing
was renamed to
RoutingRoot
while a new different
Routing
was added? Or something?
When using just
RoutingCallStarted
the IDE correctly suggests and imports
RoutingRoot.RoutingCallStarted
I also had to change
fun Routing.setupSomeStuff()
to
fun Route.setupSomeStuff()
, the intention was for this function to be forced to be called at the root of the routing definition but it no longer seem to be an option
a
I also had to change
fun Routing.setupSomeStuff()
to
fun Route.setupSomeStuff()
, the intention was for this function to be forced to be called at the root of the routing definition but it no longer seem to be an option
You can still use
Routing.setupSomeStuff
.
r
Well it didn't compile anymore because the receiver of the lambda passed to
routing {}
changed
a
The following code compiles on my machine with Ktor 3.0.0:
Copy code
fun main() {
    embeddedServer(Netty, port = 8060, host = "0.0.0.0", module = {
        routing {
            setupSomeStuff()
        }
    }).start(wait = true)
}

fun Routing.setupSomeStuff() {
    get {
        call.respondText("GET")
    }
}
r
Well I don't know, maybe my IDE lied, I'll have to try again
a
So
Routing
was renamed to
RoutingRoot
while a new different
Routing
was added? Or something?
The
Routing
is an interface and the
RoutingRoot
is a class that implements the interface.