https://kotlinlang.org logo
#ktor
Title
# ktor
u

Undervoid

09/02/2021, 7:22 AM
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

Aleksei Tirman [JB]

09/02/2021, 7:58 AM
@Rustam Siniukov do you know any better way?
r

Rustam Siniukov

09/02/2021, 9:50 AM
There is no built in API for that. What is your use case?
u

Undervoid

09/02/2021, 10:06 AM
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
3 Views