The Wayback Machine - https://web.archive.org/web/20190714165706/https://github.com/ktorio/ktor
Skip to content
Framework for quickly creating connected applications in Kotlin with minimal effort
Branch: master
Clone or download
Latest commit d1128ac Jul 12, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Rename .github/PULL_REQUEST_TEMPLATE/pull_request_template.md to .git… Jul 5, 2019
.idea Add codestyle idea files Jun 13, 2019
binary-compatibility-validator Add web assembly content type support Jul 12, 2019
gradle Add jetty alpn versions for newer java 8 updates Jul 12, 2019
jvm Migrate to kotlin-multiplatform plugin Dec 24, 2018
karma Increase mocha test timeout Jul 12, 2019
ktor-client Make client tests retry server startup if failed Jul 12, 2019
ktor-features Add kotlinx.serialization support for ContentNegotiation feature Jul 3, 2019
ktor-http Add web assembly content type support Jul 12, 2019
ktor-network Improve TLS handshake diagnostic Jul 12, 2019
ktor-server Increase server test timeout Jul 12, 2019
ktor-utils Add coroutine name to file read/writer coroutines Jul 12, 2019
.editorconfig Fix .editorconfig to append trailing newline Oct 10, 2018
.gitignore Add vim swp files to gitignore Jun 19, 2019
CHANGELOG.md Changelog Jul 12, 2019
CODE_OF_CONDUCT.md Code of conduct added Feb 15, 2019
CONTRIBUTING.md Add code of conduct to the contribution guide Jul 5, 2019
LICENSE Add missing LICENSE file Jul 7, 2017
README.md Add the code of conduct to readme Jul 5, 2019
RELEASE.md Update RELEASE.md Feb 21, 2019
build.gradle Remove browser tests hack Jul 9, 2019
gradle.properties Upgrade Jetty Jul 12, 2019
gradlew Gradle build: initial Oct 23, 2017
gradlew.bat Gradle build: initial Oct 23, 2017
pipeline.lua Upgrade dokka to 0.9.16 Apr 3, 2018
settings.gradle Add kotlinx.serialization support for ContentNegotiation feature Jul 3, 2019

README.md

Ktor

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.

You can’t perform that action at this time.