The Wayback Machine - https://web.archive.org/web/20200620063520/https://github.com/ktorio/ktor
Skip to content
Framework for quickly creating connected applications in Kotlin with minimal effort
Kotlin
Branch: master
Clone or download

Latest commit

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Official Gradle Wrapper Validation GitHub Action Jan 21, 2020
.idea JetBrains Toolbox icon (#1805) Jun 4, 2020
gradle Add flag to enable coverage Jun 3, 2020
jvm Migrate to kotlin-multiplatform plugin Dec 24, 2018
karma Increase mocha test timeout Jul 12, 2019
ktor-bom Migrate ktor-bom to java-platform plugin (#1337) Dec 5, 2019
ktor-client Fix sending blank ContentType in Apache engine Jun 19, 2020
ktor-features Add contextual serialization support Jun 10, 2020
ktor-http Parse blank content type to Any Jun 19, 2020
ktor-io Make test internal, fix exception text Jun 8, 2020
ktor-network Cleanup public API Mar 10, 2020
ktor-server JsonFeature: Fixed header behavior and made it more flexible (#1927) Jun 16, 2020
ktor-test-dispatcher Fix package directive; Add unimported cfnetwork constants Mar 19, 2020
ktor-utils JsonFeature: Fixed header behavior and made it more flexible (#1927) Jun 16, 2020
.editorconfig Fix .editorconfig to append trailing newline Oct 10, 2018
.gitignore JetBrains Toolbox icon (#1805) Jun 4, 2020
CHANGELOG.md Changelog Mar 12, 2020
CODE_OF_CONDUCT.md Code of conduct added Feb 15, 2019
CONTRIBUTING.md Fix minor grammar mistakes in the README. Mar 12, 2020
LICENSE Add missing LICENSE file Jul 7, 2017
README.md Fix minor grammar mistakes in the README. Mar 12, 2020
RELEASE.md Update RELEASE.md Sep 2, 2019
build.gradle Add flag to enable coverage Jun 3, 2020
gradle.properties Introduce non-suspend api for writing Jun 8, 2020
gradlew Upgrade Gradle to 5.6.2 Sep 27, 2019
gradlew.bat Upgrade Gradle to 5.6.2 Sep 27, 2019
settings.gradle Exclude tracing from build until Android SDK available on mac agents Jun 11, 2020

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 a GET http request for the 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 the application using a unified interception mechanism which allows building arbitrary pipelines.

Ktor Applications 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, the code looks declarative. Application composition is entirely up to the developer's choice – with functions or classes, using dependency injection framework or doing it all manually in the main function.

Asynchronous

The Ktor pipeline machinery and API are 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 applications can be hosted in a special test environment, which emulates a web server to some extent 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. Running integration tests with a 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 and the Code of conduct before contributing.

You can’t perform that action at this time.