Ktor

Ktor

Language
Kotlin
Category
9
Version
2.0.3
Authors
JetBrains
Description
Ktor is a framework for building asynchronous servers and clients in connected systems using Kotlin.
Install Instructions
  • Using Gradle(Kotlin)
repositories {
mavenCentral()
}
dependencies {
implementation("io.ktor:ktor-server-core:2.0.3")
implementation("io.ktor:ktor-server-netty:2.0.3")
}
Usage
import io.ktor.server.netty.*
import io.ktor.server.routing.*
import io.ktor.server.application.*
import io.ktor.http.*
import io.ktor.server.response.*
import io.ktor.server.engine.*
fun main(args: Array<String>) {
embeddedServer(Netty, 8080) {
routing {
get("/") {
call.respondText("Hello, world!", ContentType.Text.Html)
}
}
}.start(wait = true)
}
  • Runs embedded web server on localhost:8080
  • Installs routing and responds with "Hello, world!" when receiving a GET http request for the root path
Links