Ktor is the asynchronous web framework for Kotlin created by JetBrains. It is written in Kotlin and its machinery and API is utilizing Kotlin coroutines. It's unopinionated design makes it a very good choice for development of applications composed of many different technologies. Since both Ktor and KVision are based on coroutines, the plugging of KVision's server module into Ktor's pipeline is executed in a natural and efficient way.
Build configuration
The integration with Ktor is contained in the kvision-server-ktor module. It has to be added as the dependency in the backend target. This module depends on the ktor-server-core, ktor-jackson, jackson-module-kotlin and guice libraries. Any other dependencies can be added to build.gradle.kts and then be used in your application.
Note: You can use other engines instead of Netty - see Ktor documentation. Remember to add the appropriate dependency.
Application configuration
The standard way to configure Ktor application is src/backendMain/resources/application.conf file. Among other options it contains the name of the main function of your app.
The integration module utilizes Guice and you can access external components and resources by injecting server objects into your class. KVision allows you to inject Application and ApplicationCall instances. These objects give you access to the application configuration, its state, the current request and the user session (if it is configured).
You can also inject other Guice components, defined in your application and configured in custom Guice modules or with just-in-time bindings.
Note: The new instance of the service class will be created by Guice for every server request. Use application, session or call objects to store your state with appropriate scope.
Blocking code
Since Ktor architecture is asynchronous and non-blocking, you should never block a thread in your application code. If you have to use some blocking code (e.g. blocking I/O, JDBC) always use the dedicated coroutine dispatcher.
This function is the application starting point. It's used to initialize and configure application modules and features. Minimal implementation for KVision integration contains kvisionInit and applyRoutes function calls.
The kvisionInit function can take multiple parameters of type com.google.inject.Module. It allows you to register custom modules inside the main Guice injector.