Ktor is a framework to easily build connected applications – web applications, HTTP services, mobile and browser applications. Modern connected applications need to be asynchronous to provide the best experience to users, and Kotlin coroutines provide awesome facilities to do it in an easy and straightforward way.
Set up a Ktor project
The plugin allows you to create a Ktor project as well as start.ktor.io, but with the additional convenience of being fully integrated in the IDE.
1) In a first step, you can configure the project to generate and select features to install:
2) In a second step, you can configure the project artifacts:
And that's it. A new project will be created and opened inside your IDE.
A simple hello world in Ktor looks like this:
Here you define a plain callable main method.
Then you create an embedded server using Netty as the back-end that will listen on port 8080.
Installs the routing feature with a block where you can define routes for specific paths and HTTP methods.
Actual routes: In this case, it will handle a GET request for the path
/demo, and will reply with a
Actually start the server and wait for connections.
Accessing your application
Since you have a main method, you can execute it with your IDE. That will open a HTTP server, listening on http://127.0.0.1:8080, You can try opening it with your favorite web browser.
At this point you should have a very simple Web Back-end running, so you can make changes, and see the results in your browser.