Ktor — Async Web Framework for Kotlin by JetBrains
Ktor is a framework for quickly creating connected applications in Kotlin with minimal effort. Built by JetBrains, it supports coroutines natively, runs on multiple engines (Netty, CIO, Jetty), and works for server + client HTTP in Kotlin Multiplatform.
What it is
Ktor is a framework by JetBrains for building connected applications in Kotlin with minimal effort. It supports coroutines natively, runs on multiple engines (Netty, CIO, Jetty), and works for both server-side HTTP and client-side HTTP in Kotlin Multiplatform projects.
Ktor is designed for Kotlin developers who want a lightweight, non-opinionated framework that leverages Kotlin's language features rather than imposing its own abstractions.
How it saves time or tokens
Ktor's plugin-based architecture means you only include what you need. There is no framework boilerplate for features you do not use. Native coroutine support makes async I/O straightforward without callback hell. The same HTTP client works across JVM, Android, iOS, and JavaScript targets via Kotlin Multiplatform.
How to use
- Create a project via IntelliJ IDEA or Gradle
- Add Ktor dependencies to
build.gradle.kts:
plugins {
id("io.ktor.plugin") version "3.0.0"
kotlin("plugin.serialization") version "2.0.0"
}
dependencies {
implementation("io.ktor:ktor-server-core")
implementation("io.ktor:ktor-server-netty")
implementation("io.ktor:ktor-server-content-negotiation")
implementation("io.ktor:ktor-serialization-kotlinx-json")
}
- Write your server:
fun main() {
embeddedServer(Netty, port = 8080) {
install(ContentNegotiation) { json() }
routing {
get("/hello") {
call.respond(mapOf("message" to "Hello, Ktor"))
}
}
}.start(wait = true)
}
Example
// Full REST API with serialization
@Serializable
data class Task(val id: Int, val title: String, val done: Boolean)
fun Application.configureRouting() {
val tasks = mutableListOf(
Task(1, 'Build API', false),
Task(2, 'Write tests', false)
)
routing {
get("/tasks") { call.respond(tasks) }
post("/tasks") {
val task = call.receive<Task>()
tasks.add(task)
call.respond(HttpStatusCode.Created, task)
}
}
}
Related on TokRepo
- API tools — API development frameworks
- AI coding tools — development productivity resources
Common pitfalls
- Forgetting to install the ContentNegotiation plugin, which causes serialization to silently fail
- Mixing blocking I/O calls inside coroutine handlers, which blocks the event loop
- Not configuring CORS when building APIs consumed by browser frontends
Frequently Asked Questions
Ktor is lightweight and non-opinionated, using a plugin system where you add only what you need. Spring Boot provides a comprehensive ecosystem with convention-over-configuration. Ktor is better for microservices and Kotlin-first projects; Spring Boot is better for enterprise Java ecosystems.
Yes. Ktor has a built-in WebSocket plugin for both server and client. Server-side WebSockets support coroutine-based message handling, making it natural to write async real-time applications in Kotlin.
The Ktor HTTP client works across JVM, Android, iOS, JavaScript, and native targets via Kotlin Multiplatform. The server side runs on JVM targets (Netty, CIO, Jetty engines).
Ktor supports Netty (most popular, production-ready), CIO (Kotlin-native coroutine-based), Jetty (servlet-based), and Tomcat. Each engine has different performance characteristics and deployment requirements.
Yes. Ktor is maintained by JetBrains and used in production by many companies. It follows semantic versioning with stable API guarantees. The 3.x release line is the current stable version.
Citations (3)
- Ktor GitHub— Ktor framework by JetBrains
- Ktor Documentation— Ktor server and client documentation
- Kotlin Documentation— Kotlin coroutines for async programming
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.