Created
March 8, 2019 15:03
-
-
Save mattrussell-sonocent/faa63a417fd3b3f7424de93d4a5e7d1f to your computer and use it in GitHub Desktop.
Ktor example
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.Application | |
import io.ktor.application.call | |
import io.ktor.application.install | |
import io.ktor.features.ContentNegotiation | |
import io.ktor.http.ContentType | |
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 | |
data class Credentials(val username: String, val password: String) | |
fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args) | |
@Suppress("unused") // Referenced in application.conf | |
@kotlin.jvm.JvmOverloads | |
fun Application.module(testing: Boolean = false) { | |
install(ContentNegotiation) { | |
jackson { | |
enable(SerializationFeature.INDENT_OUTPUT) | |
} | |
} | |
routing { | |
get("/") { | |
call.respondText("HELLO WORLD!", contentType = ContentType.Text.Plain) | |
} | |
post("/login") { | |
val credentials = call.receive<Credentials>() | |
call.respond(credentials) | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment