Once installed, I right clicked on the extension and chose "Inspect in WebStorm" option. Then I installed the JetBrains IDE Support Chrome Extension.
Val id = call.parameters ?: call.respondText(ĬustomerStorage.I finally got it to work after much trial and error.
This corresponds to the Application.module() function in Application.kt, which currently doesn't do anything: Our nf configures the entry point of our application to be .ApplicationKt.module. If you'd like to learn more about logging in Ktor, check out the Logging topic. If you'd like to learn more about how a Ktor server is configured, check out the Configuration help topic.Īlso included in the same folder is a logback.xml file, which sets up the basic logging structure for our server. Ktor uses this file to determine the port on which it should run, and it also defines the entry point of our application. The repository also includes a basic nf in HOCON format, located in the resources folder. We will use this to define unit tests for our project.Ĭonfigurations: nf and logback.xml Ktor-server-test-host allows us to test parts of our Ktor application without having to use the whole HTTP stack in the process. In order to use ktor-serialization, we also have to apply the .serialization plugin. We will use it to format our APIs output, and to consume user input that is structured in JSON. Ktor-serialization provides a convenient mechanism for converting Kotlin objects into a serialized form like JSON, and vice versa. Logback-classic provides an implementation of SLF4J, allowing us to see nicely formatted logs in our console.
Ktor-server-netty adds the Netty engine to our project, allowing us to use server functionality without having to rely on an external application container. Ktor-server-core adds Ktor's core components to our project. Let's briefly go through these dependencies one-by-one: TestImplementation "io.ktor:ktor-server-test-host:$ktor_version" Implementation "io.ktor:ktor-serialization:$ktor_version" Implementation "ch.qos.logback:logback-classic:$logback_version"
Implementation "io.ktor:ktor-server-netty:$ktor_version" Implementation "io.ktor:ktor-server-core:$ktor_version" Dependenciesįor this hands-on, the dependencies block in our adle file is probably the most interesting part: It is still beneficial to understand what artifacts are being used for the application, so let's have a closer look at our project template and the dependencies and configuration it relies on. Because it already contains all dependencies that we will need throughout the hands-on, you don't need to make any changes to the Gradle configuration. The template repository contains a basic Gradle projects for us to build our project. Please clone the project repository from GitHub, and open it in IntelliJ IDEA. If we were to start a fresh idea from zero, Ktor would have a few ways of setting up a preconfigured Gradle project: and the Ktor IntelliJ IDEA plugin make it easy to create a starting-off point for projects using a variety of features from the framework.įor this tutorial, however, we have made a starter template available that includes all configuration and required dependencies for the project.
You can find the template project as well as the source code of the final application on the corresponding GitHub repository. For other styles and options check out the Routing in Ktor help topic. They certainly aren't the only ways to define routes in applications, but they showcase differently maintainable approaches. We will be using two ways to define routes and organize these by files. We will build a convenient way of listing all customers & orders in our system, get information for individual customers & orders, and provide functionality to add new entries and remove old entries. Throughout the hands-on, we'll build a simple JSON API that allows us to query information about the customers of our fictitious business, as well as the orders we currently want to fulfill. We will see how routes are defined and structured, how serialization plugins (formerly known as features) help with simplifying tedious tasks, and how we can test parts of our application both manually and automated. In this hands-on, we're going to create an HTTP API using Kotlin and Ktor that can serve as a backend for any application, be it mobile, web, desktop, or even a B2B service.