Klite: a very light-weight (lite) non-blocking http framework for Kotlin coroutines on JVM. Probably the most sustainable JVM web framework (low resource usage and CO₂ emissions).
Inspired by SparkJava, Jooby, etc, but smaller, simpler and better.
Includes very light json and jdbc & migrations submodules for Kotlin, which can be used independently.
Please star the repo to let us know you are interested.
See the Tutorial to grasp the basics quickly.
@GET suspend fun route() = provider.fetchData()
These integrate with external libraries. All of this functionality is available in Klite's own modules.
The main server module is only ~1000 lines of code.
Klite powers a number of known production apps already. Publicly announced at KKON 2022, see the slides.
Klite (including jdk.httpserver) has sub-1ms overhead per request after warmup. Can be verified with Apache Benchmark after the sample project is launched:
This simple route produces ~19000 rps, with 99% taking less than 1ms:
ab -n 10000 -c 10 http://localhost:8080/api/hello
JDBC access route produces ~11000 rps, with 99% taking less than 1ms:
ab -n 10000 -c 10 http://localhost:8080/api/hello/user/9725b054-426b-11ee-92a5-0bd2a151eea2
Coroutine suspension test with 1000 concurrent requests, ~7000 rps, 80% of requests complete within the specified delay of 100ms:
ab -n 10000 -c 1000 http://localhost:8080/api/hello/suspend
Tests ran on Ubuntu, Java 20, i9-9900T CPU from 2019.
See the sample project on how to build apps with Klite and run them in Docker.
Klite builds are available from jitpack, see also changelog
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
dependencies {
val kliteVersion = "master-SNAPSHOT" // you can put a released tag or commit hash here
implementation("com.github.codeborne.klite:klite-server:$kliteVersion")
// Plus any optional components with their own external dependencies, see above for list
implementation("com.github.codeborne.klite:klite-jackson:$kliteVersion")
implementation("com.github.codeborne.klite:klite-jdbc:$kliteVersion")
testImplementation("com.github.codeborne.klite:klite-jdbc-test:$kliteVersion")
...
}
Jitpack builds requested versions on the fly, so it is also good if you want to fork Klite and customize for your own needs - you will still be able to add your fork as a Maven/Gradle dependency in your apps.
But pull-requests are welcome if you want to improve something for everybody!
Publish to ~/.m2/repository
by running ./gradlew publishToMavenLocal
Then add mavenLocal()
repository to your project and use Klite version of master-SNAPSHOT
.
If there is a problem with Jitpack, then it's possible to add the following to your settings.gradle.kts
:
sourceControl {
gitRepository(java.net.URI("https://github.com/codeborne/klite.git")) {
producesModule("com.github.codeborne.klite:server")
producesModule("com.github.codeborne.klite:jdbc")
// list all subprojects you depend on in build.gradle.kts, use their unprefixed names, e.g. server, not klite-server
}
}
Gradle will clone and build Klite for you automatically during your project's build. Tagged version numbers are supported this way, but not commit hashes.