Ktor 1.6.2 Help

A Ktor application

Ktor can be used to create a variety of server and client-side applications. Whether we want to create a website that serves static and dynamic pages, an HTTP endpoint, a RESTful system, or even microservices, Ktor makes it all possible.

In this section, we're going to cover the basics of what a Ktor Server Application is and how the pieces all fit together.

The simplest Ktor application

One of Ktor's goals is to remain as simple as possible and to avoid any kind of magic. The equivalent to a Hello World application in Ktor would be:

fun main() { embeddedServer(Netty, port = 8000) { routing { get("/") { call.respondText("Hello, world!") } } }.start(wait = true) }

We start by creating a server, in this case using Netty as an Engine, and setting the port to 8000. After this, we define a route to respond to requests made to / with a simple Hello, world! text. Finally, we start the server.

Next steps

In the next chapters, we'll take a look at the main concepts of creating a Ktor application - from configuring a server to using plugins, which is core to all Ktor applications:

Last modified: 19 July 2021