Ktor Quick setup

Quick setup — Ktor

Vikram Hooda

--

Setup a new project and run the application to print “Hello KTOR World!”

New project wizard

When you create a new project, you interact first with the new project wizard where you will select the option for your feature. Features you select will be installed by default into the default Application file(Application.kt) as shown below image.

Default project structure

To run this project, either run with green icon marked for main() function or select choose Run → run from the toolbar. It will prompt a dialog with an application name to choose. Choose application name and it will start the server.
Also, Once you hit “Add configuration” you will see “Run/debug configuration” dialog. Choose the application you ran the first time and in Main Class field replace with default server class to run the server i.e. See image below

io.ktor.server.netty.EngineMain
Edit configuration with the default server class name ie EngineMain

After running the application, you will see the server running hostname along with port as shown in the image below. I used port 8888 and you can edit into the application.config file under resource directory.

That’s all for this story. I would cover routing and location features in detail in the next post.

Let’s make happily coding journey with a clap. :-)

--

--