Hello there, is there any way to get all route pat...
# ktor
u
Hello there, is there any way to get all route path on service startup ? I found someone talked about this, however I’m not sure it’s the best practice to do it https://github.com/ktorio/ktor/issues/1252#issuecomment-551304202
Copy code
fun Application.ktorMain() {
    // set up omitted
    val root = feature(Routing)
    val allRoutes = allRoutes(root)
    val allRoutesWithMethod = allRoutes.filter { it.selector is HttpMethodRouteSelector }
    allRoutesWithMethod.forEach {
        <http://logger.info|logger.info>("route: $it")
    }
}

fun allRoutes(root: Route): List<Route> {
    return listOf(root) + root.children.flatMap { allRoutes(it) }
}
is there another approach to do it ?
👍 1
👀 1
a
@Rustam Siniukov do you know any better way?
r
There is no built in API for that. What is your use case?
u
I’m trying to build a configuration page which allowed user to change the call response for all route requests. so I need to get list of routes on service startup then display them in the front page