https://kotlinlang.org logo
Title
a

Ananiya

11/02/2020, 6:23 AM
hello, how can i convert this spring webhook
data class WR(status: String)
    @RestController
    @RequestMapping("/webhook")
    class WebhookController {

        @PostMapping
        fun postMessage(@RequestBody json: String) : WebhookResponse {
            return WR("ok")
        }
    }
to ktor , i am little bit confused
a

Ali Albaali

11/02/2020, 9:39 AM
data class WR(status: String)
fun Routing.webhookController() {
route("/webhook") {
post {
val body = call.recieveOrNull<Map<String,String>>()
val json = body?.get("json") as String
val response = WR("ok")
call.respond(HttpStatusCode.OK, response)
}
}
}
👍 1
a

Ananiya

11/02/2020, 9:42 AM
Thanks Ok, let me try
@Ali Albaali recieveOrNull is not working
a

Ali Albaali

11/02/2020, 10:10 AM
oh it's
receiveOrNull
you can also use just
receive<Map<String,String>>()
a

Ananiya

11/02/2020, 11:05 AM
@Ali Albaali where to run it or like this
fun main(){
  embeddedServer(Netty, port = 8080){
      routing {
          webhookController()
     }.start(wait = true)
}
a

Ali Albaali

11/02/2020, 11:11 AM
Yep you can run it like that
a

Ananiya

11/03/2020, 6:28 PM
@Ali Albaali finally it got to work, thanks for your effort 😀😊
👋 1
a

Ali Albaali

11/03/2020, 7:37 PM
You're welcome
👍 1