Last active
August 15, 2019 18:43
-
-
Save kaue-silva-ifood/bc6c9ffe520ec12da6e5d3b49701d35e to your computer and use it in GitHub Desktop.
Application kt, with status page and Jackson
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
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