How Ktor works: Core Principles
mainKtor is designed around three main pillars:
- Unopinionated: Ktor does not force specific technologies for logging, persistence, or serialization. It uses a unified interception mechanism to install features into an application, allowing you to build arbitrary pipelines. It can be hosted in servlet containers (like Tomcat) or standalone (using Netty or Jetty).
- Asynchronous: The framework and its API are built on Kotlin coroutines, providing an asynchronous programming model. All host implementations use asynchronous I/O to prevent thread blocking.
- Testable: Ktor provides a special test environment that emulates a web server without actual networking. This allows for high-performance integration testing without heavy mocking.