Created
August 15, 2019 19:17
-
-
Save kaue-silva-ifood/9bb5eef07a0d71338b8aa459a3f66bf9 to your computer and use it in GitHub Desktop.
Application.kt with resquest class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example | |
import com.fasterxml.jackson.databind.SerializationFeature | |
import io.ktor.application.* | |
import io.ktor.features.ContentNegotiation | |
import io.ktor.features.StatusPages | |
import io.ktor.http.ContentType | |
import io.ktor.http.HttpStatusCode | |
import io.ktor.jackson.jackson | |
import io.ktor.request.receive | |
import io.ktor.response.respond | |
import io.ktor.response.respondText | |
import io.ktor.routing.get | |
import io.ktor.routing.post | |
import io.ktor.routing.routing | |
import io.ktor.server.engine.embeddedServer | |
import io.ktor.server.netty.Netty | |
fun main(args: Array<String>) { | |
embeddedServer(Netty, 8080) { | |
install(StatusPages) { | |
exception<Throwable> { e -> | |
call.respondText(e.localizedMessage, ContentType.Text.Plain, HttpStatusCode.InternalServerError) | |
} | |
} | |
install(ContentNegotiation) { | |
jackson { | |
enable(SerializationFeature.INDENT_OUTPUT) | |
} | |
} | |
routing { | |
get("/") { | |
call.respond(Response(status = "OK")) | |
} | |
post("/"){ | |
val request = call.receive<Request>() | |
call.respond(request) | |
} | |
} | |
}.start(wait = true) | |
} | |
data class Request (val id : String, | |
val quantity: Int, | |
val isTrue: Boolean | |
) | |
data class Response(val status: String) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment