Search⌘ K
AI Features

Starting the Server

Explore how to start a Ktor server by adding code to the main App.kt file, using embeddedServer with Netty or CIO engines. Understand the Builder, Factory, and Bridge design patterns that enable flexible server configuration and component interchangeability in Kotlin microservices.

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 that will respond with OK ...