fcosta
12/17/2018, 12:33 AMUnsupportedMediaTypeException
when try to parse the body. Do you know what i’m doing wrong? I just followed the documentation: <https://ktor.io/servers/calls/requests.html#typed-objects>
fun main() {
embeddedServer(Netty, port = 8080, watchPaths = listOf(""), module = Application::module).start()
}
fun Application.module() {
install(StatusPages) {
exception<Throwable> {
call.respondText(it.localizedMessage, ContentType.Text.Plain, HttpStatusCode.InternalServerError)
}
}
install(ContentNegotiation) {
gson()
}
routing {
get("/") {
call.respondText("Hello World", ContentType.Text.Html)
}
post("/verify") {
val request = call.receive<Request>()
call.respond(request)
}
}
}
data class Request(val userId: String, val productId: String)
data class Response(val status: String)
Riccardo Montagnin
12/17/2018, 8:52 AMfcosta
12/17/2018, 12:09 PMcurl -v -H "Content-Type: application/json" -X POST -d '{"userId":"42","productId":"5"}' <http://localhost:8080/verify>