QuickStart

    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 provideawesome facilities to do it in an easy and straightforward way.

    While not yet entirely there, the goal of Ktor is to provide an end-to-end multiplatform application framework for connected applications. Currently, JVM client and server scenarios are supported, as well as JavaScript, iOS and Android clients, and we are working on bringing server facilities to nativeenvironments, and client facilities to other native targets.

    Table of contents:

    You can set up a Ktor project using , Gradle, and the IntelliJ Plugin.

    2) In a second step, you can configure the project artifacts:

    Quick Start - 图1

    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.
    • Actual routes: In this case, it will handle a GET request for the path , and will reply with a message.
    • Actually start the server and wait for connections.

    Main.kt

    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.

    If that doesn’t work, maybe your computer is using that port already. You can try changing theport 8080 (in line 10) and adjust it as needed.

    Since you have configured a Gradle project with the application plugin and the ,you can also run it from a terminal using on Linux/Mac, or on a Windows machine.