Skip to content

Instantly share code, notes, and snippets.

@kaue-silva-ifood
Last active August 15, 2019 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaue-silva-ifood/bc6c9ffe520ec12da6e5d3b49701d35e to your computer and use it in GitHub Desktop.
Save kaue-silva-ifood/bc6c9ffe520ec12da6e5d3b49701d35e to your computer and use it in GitHub Desktop.
Application kt, with status page and Jackson
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.response.respond
import io.ktor.response.respondText
import io.ktor.routing.get
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"))
}
}
}.start(wait = true)
}
data class Response(val status: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment