zwartzon / klite

Kotlin async http server framework with coroutines and zero deps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Klite

Build & Test

A very light-weight (lite) non-blocking http framework for Kotlin coroutines on JVM.

Inspired by SparkJava, Jooby, etc, but smaller, simpler and better.

Goals

  • 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.

Dependencies

  • Java 6+ built-in non-blocking jdk.httpserver
  • Re-routable Java 9+ System.Logger

Modules

  • server - the main server module. See it's docs. Zero external dependencies.
  • jackson - adds json parsing/rendering using Jackson
  • serialization - adds json parsing/rendering using kotlinx-serialization
  • slf4j - redirects server logs to slf4j and configures it
  • i18n - simple server-side translations (for emails, etc)
  • jdbc - provides jdbc extensions and transaction handling (depends on slf4j because of Hikari)
  • jdbc-test - provides a way of testing your DB code using a real DB
  • jobs - provides a simple scheduled JobRunner
  • liquibase - allows to use liquibase for DB migration

Status

The core server is less than 1000 lines of code.

Klite powers a few production apps already. Public announcement at KKON 2022, see the slides.

Usage

See the sample subproject on how to build apps with Klite and run them in Docker.

Klite builds are available from jitpack.

Release

  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")
    ...
  }

Using unreleased commits

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!

About

Kotlin async http server framework with coroutines and zero deps

License:MIT License


Languages

Language:Kotlin 100.0%