Klite: a very light-weight (lite) non-blocking http framework for Kotlin coroutines on JVM.
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.
- Proper Kotlin coroutine support with working before/after filters for e.g. transactions and logging
- Minimal amount of code
- Simple to maintain & change
- Performance is also important, but simplicity is preferred
- Zero dependencies - Java built-in jdk.httpserver is used under the hood
- Perfect for microservices
- But still possible to easily add support for other servers if needed
- Sample docker image is about 50-70Mb thanks to jlink, depending on used modules
- 12-factor apps by default
- Most behaviour can be overridden if necessary
- Both route builder and annotated classes
- Very easy to do simple things, e.g.
@GET suspend fun route() = provider.fetchData()
- Most app code will not depend on the framework, easy to switch
- Not much need for documentation - the source code is short and readable.
- Java 6+ built-in non-blocking jdk.httpserver
- Re-routable Java 9+ System.Logger
- core - some reusable classes, e.g. Config. Don't depend on it directly.
- server - the main server module. See it's docs. Zero external dependencies.
- json - lightweight and easily configurable json parsing/rendering (usable standalone)
- csv - simple CSV parsing/generation (usable standalone)
- i18n - simple server-side translations (for emails, etc)
- jdbc - provides JDBC extensions for DB access, transaction handling and migrations (usable standalone)
- jdbc-test - provides a way of testing your DB code using a real DB
- jobs - provides a simple scheduled JobRunner
- openapi - generates OpenAPI 3.0 spec for all routes in a context, viewable with Swagger UI
These integrate with external libraries. All of this functionality is available in Klite's own modules.
- slf4j - redirects server logs to slf4j and configures it
- jackson - json parsing/rendering using Jackson
- serialization - json parsing/rendering using kotlinx-serialization
- liquibase - allows to use Liquibase for DB migration
The main server module is only ~1000 lines of code.
Klite powers a few known production apps already. Publicly announced at KKON 2022, see the slides.
See the sample subproject 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.