Server-Side Kotlin with Ktor · Hello, Ktor: | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/2885892-server-side-kotlin-with-ktor/lessons/2

The application fails to run with the most up-to-date Ktor version (v1.2.0):

Thanks for the comment @rajohns! The sample project for the course was developed using Ktor 1.1.3. There were breaking changes recently introduced in 1.2.0. When available, we’ll post a 1.2.X version of the sample project code, but your best bet for now for following along with the course is to select 1.1.3, 1.1.4, or 1.1.5 when creating the course project. Thanks again!

ok, sounds good thanks! loving the the course so far, keep up the good work!

Use below code in you Application.kt and everything will run smooth:

import io.ktor.application.*
import io.ktor.http.ContentType
import io.ktor.response.*
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) {
        routing {
            get("/") {
                call.respondText("Hello, world!", ContentType.Text.Html)
            }
        }
    }.start(wait = true)
}