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

bjonnh

05/09/2019, 4:14 PM
what is a clean way to have the same code for get("/") and post("/") ?
d

Dominaezzz

05/09/2019, 5:13 PM
Define the lambda beforehand and then pass it to both?
p

Paulius Ruminas

05/09/2019, 5:57 PM
Just wondering what's the use case to have both get and post for the same url if you will handle them in the same way.
b

bjonnh

05/09/2019, 6:02 PM
because a service I do not have control over uses get for small requests and post for large
Trying to make a lambda would force me to make a suspend lambda and I can't find a way to write it
Copy code
val foo = fun PipelineContext<Unit, ApplicationCall>.(it: Unit) {
            val query = call.receiveParameters()["query"]
            val content = "test"
            call.respondText(
                content
                , ContentType.Text.Plain
            )
        }
Copy code
suspend fun request(ctx: PipelineContext<Unit, ApplicationCall>) {
            val query = ctx.call.receiveParameters()["query"] …} 
post("/") { request(this) }
works like that