Ktor

以最小的工作量在 Kotlin 中快速创建连接应用程序的框架。「Framework for quickly creating connected applications in Kotlin with minimal effort」

Official JetBrains project
Download
TeamCity Build
GitHub License

Ktor is a framework for quickly creating web applications in Kotlin with minimal effort.

import io.ktor.server.netty.*
import io.ktor.routing.*
import io.ktor.application.*
import io.ktor.http.*
import io.ktor.response.*
import io.ktor.server.engine.*

fun main(args: Array<String>) {
    embeddedServer(Netty, 8080) {
        routing {
            get("/") {
                call.respondText("Hello, world!", ContentType.Text.Html)
            }
        }
    }.start(wait = true)
}
  • Runs embedded web server on localhost:8080
  • Installs routing and responds with Hello, world! when receiving GET http request for root path

Principles

Unopinionated

Ktor Framework doesn't impose a lot of constraints on what technology a project is going to use – logging,
templating, messaging, persistent, serializing, dependency injection, etc.
Sometimes it may be required to implement a simple interface, but usually it is a matter of writing a
transforming or intercepting function. Features are installed into application using unified interception mechanism
which allows building arbitrary pipelines.

Ktor Application can be hosted in any servlet container with Servlet 3.0+ API support such as Tomcat, or
standalone using Netty or Jetty. Support for other hosts can be added through the unified hosting API.

Ktor APIs are mostly functions calls with lambdas. Thanks to Kotlin DSL capabilities, code looks declarative.
Application composition is entirely developer's choice – with functions or classes, using dependency injection
framework or doing it all manually in main function.

Asynchronous

Ktor pipeline machinery and API is utilising Kotlin coroutines to provide easy-to-use asynchronous
programming model without making it too cumbersome. All host implementations are using asynchronous I/O facilities
to avoid thread blocking.

Testable

Ktor application can be hosted in a special test environment, which emulates to some
extent web server without actually doing any networking. It provides easy way to test an application without mocking
too much stuff, and still achieve good performance while validating application calls. Integration tests with real
embedded web server are of course possible, too.

Documentation

Please visit ktor.io for Quick Start and detailed explanations of features, usage and machinery.

  • Getting started with Gradle
  • Getting started with Maven
  • Getting started with IDEA

Inspirations

Kotlin web frameworks such as Wasabi and Kara, which are currently deprecated.

Reporting Security Vulnerabilities

If you find a security vulnerability in Ktor, we kindly request that instead of using our public issue tracker, you instead reach out to the JetBrains security team via our responsible disclosure process.

Contributing

Please see the contribution guide before contirbuting and Code of conduct.

主要指标

概览
名称与所有者ktorio/ktor
主编程语言Kotlin
编程语言Kotlin (语言数: 8)
平台
许可证Apache License 2.0
所有者活动
创建于2015-08-03 16:49:36
推送于2025-06-12 14:10:25
最后一次提交
发布数173
最新版本名称3.1.3 (发布于 )
第一版名称ktor-0.1.2 (发布于 2015-11-11 17:41:09)
用户参与
星数13.7k
关注者数173
派生数1.1k
提交数6.1k
已启用问题?
问题数1478
打开的问题数132
拉请求数2593
打开的拉请求数33
关闭的拉请求数813
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?