ktor

Framework for quickly creating connected applications in Kotlin with minimal effort

Subscribe to updates I use ktor


Statistics on ktor

Number of watchers on Github 2396
Number of open issues 71
Average time to close an issue about 1 month
Main language Kotlin
Average time to merge a PR 5 days
Open pull requests 24+
Closed pull requests 27+
Last commit 10 months ago
Repo Created over 3 years ago
Repo Last Updated 10 months ago
Size 9.16 MB
Homepage http://ktor.io
Organization / Authorktorio
Contributors2
Page Updated
Do you use ktor? Leave a review!
View open issues (71)
View ktor activity
View TODOs for ktor (25)
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating ktor for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

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.

ktor open issues Ask a question     (View All Issues)
  • about 2 years CallLogger fails to intercept exceptions
  • about 2 years `TODO()` should map to 501 rather than 500
  • about 2 years Exception in Route.handle is handled silently
  • over 2 years Missing Accept header should match any header("Accept", "…") selector
  • over 2 years Basic authentication does not work on first attempt
  • over 2 years Create sample using Guice as DI
  • over 2 years Consider using Transform engine to convert request content
  • over 2 years Clean `response` API
  • over 2 years Simple API for serving custom status/error pages from file system
  • over 2 years Convert custom status pages functions into a feature
  • over 2 years Locations: Support trailing /
  • over 2 years Locations: Create a convention for creating no-value query parameters
  • over 2 years You-kube sample doesn't refresh list of videos after uploading
ktor open pull requests (View All Pulls)
  • Jackson support
  • Kobalt
  • Added MapApplicationConfig.putList for ease of use.
  • Location classes with List property cannot be routed to with zero url…
  • Failing testcase with too much escaping in location values.
  • Failing testcase with empty string valued path parameter.
  • Modifying test to address property sslPort
  • Fix documentation
  • Add missing 418 status code
  • Fix MapApplicationConfig.propertyOrNull() and additional tests.
  • Extract GSON serializer from ktor-client-json as ktor-client-gson
  • Default Accept-Charset from ISO-8859-1 to UTF-8
  • Adding readme file with usage instructions
  • Add kdoc documentation for Sessions feature
  • Mark dsl functions with annotations
  • Fix feature key name
  • Make ktor-auth depend on ktor-client-core instead of the apache one
  • Added Kdoc for experimental locations feature
  • Fixes imports in the example on README
  • Rename `CommandLine.kt` to `DevelopmentEngine.kt`
  • Make formAuthentication.verfify suspendable
  • Set cookie's domain and path on sessions.clear()
  • Updates .idea run configurations
  • Work in progress: Moving ktor-samples to a separate repository
ktor list of languages used
Other projects in Kotlin