Starting the Server
Learn how to start the server in a Ktor application with the CIO server engine.
We'll cover the following...
Adding code to App.kt
file
Now, let’s add the following content to our main file, the App.kt
file (in some cases, it could be server.kt
). We can follow the path in the directory on the left side of the IDE—/CatsHostel/app/src/main/kotlin/catshostel/App.kt
—to see the code:
fun main() {
embeddedServer(Netty, port = 8080) {
routing {
get("/") {
call.respondText("OK")
}
}
}.start(wait = true)
println("open http://localhost:8080")
}
That’s all the code we need to write to start a web server ...