What is the best practice to abstract out the body...
# ktor
z
What is the best practice to abstract out the body handler?
j
One approach is to create 
Route
 extension function....something like
Copy code
fun Route.apiRoute() {

    route("/api") {
        get("/interests") {
            call.respondText("hello world")
        }
    }
}
then you'd have
Copy code
routing {
    apiRoute()
}
👍 2
z
aha..wow
Man...and that is possible?
so elegant.....
thanks a lot @John O'Reilly
e
A bit late but I usually do this in my projects: Types.kt
Copy code
typealias RouteHandler = suspend PipelineContext<Unit, ApplicationCall>.(Unit) -> Unit
Handlers.kt
Copy code
val helloWorld: RouteHandler = {
    call.respondText("hello world")
}
Routes.kt
Copy code
routing {
    route("/api") {
        get("/interests", helloWorld)
    }
}