Effortless REST API Development with Kotlin
A configuration-free, embeddable web server for Kotlin and the JVM - the port of GenHTTP, built on coroutines and virtual threads.
implementation("org.genhttp:genhttp-full:11.1.0.3")
Open source under the MIT license, on Maven Central for JDK 25 and later.
Service
import org.genhttp.engine.internal.Host
import org.genhttp.modules.functional.*
import org.genhttp.modules.practices.*
// http://localhost:8080/users/42
suspend fun main() {
val api = Inline.create()
.get("/users/:id") { id: Int -> User(id, "Jane") }
Host.create()
.handler(api)
.defaults()
.run()
}
data class User(val id: Int, val name: String)Open API
import org.genhttp.engine.internal.Host
import org.genhttp.modules.functional.*
import org.genhttp.modules.openapi.*
import org.genhttp.modules.practices.*
// http://localhost:8080/openapi.json
suspend fun main() {
val api = Inline.create()
.get("/users/:id") { id: Int -> User(id, "Jane") }
.addOpenApi()
Host.create()
.handler(api)
.defaults()
.run()
}
data class User(val id: Int, val name: String)JWT
import org.genhttp.engine.internal.Host
import org.genhttp.modules.authentication.*
import org.genhttp.modules.functional.*
import org.genhttp.modules.openapi.*
import org.genhttp.modules.practices.*
suspend fun main() {
val auth = BearerAuthentication.create()
.issuer("https://sso.example.com/")
val api = Inline.create()
.get("/users/:id") { id: Int -> User(id, "Jane") }
.addOpenApi()
.add(auth)
Host.create()
.handler(api)
.defaults()
.run()
}
data class User(val id: Int, val name: String)More
31 modules on Maven Central, among them
Real time
Security
A web server you add like any other library
No configuration files, no hosting model to learn. genhttp-kt is a library you depend on, configure in code and run wherever your application runs.
Fast Development
Write a web service in a few lines of Kotlin, with the IDE you know - IntelliJ IDEA, Fleet or VS Code. Handlers are plain functions and classes, data classes become JSON.
Kotlin-Native
Handlers are suspend functions. Every connection runs as a coroutine - on virtual threads with the internal engine, where blocking code is fine, or on the Netty event loop that accepted it. Flows and channels work on both.
Simple & Powerful
A simple, yet powerful module system. Supports widely used standards such as Open API, WebSockets, Server Sent Events or JWT authentication.
Flexible Hosting
Embed the tiny engine into an existing JVM application - a desktop app, a CLI tool, a test suite - or ship it in a Docker container. No configuration files or other magic.
Minimal Footprint
The internal engine and the core modules need nothing but the Kotlin standard library, kotlinx.coroutines and the SLF4J API. Everything else comes with the modules - or the engine - you add.
Open Source
All sources are available on GitHub under the MIT license, like GenHTTP itself. Contributions welcome.
One of the fastest Kotlin web servers for HTTP/1.1
According to HTTP Arena, genhttp-kt is among the fastest Kotlin web servers for HTTP/1.1: with the Netty engine it ranks second of all the Java and Kotlin frameworks without tuning, and the internal engine is still 1.4 times faster than Ktor and 2.6 times faster than Spring Boot.
One application, two engines
Replace the HTTP engine without touching your application code - change the dependency and the package of the Host you import.
GenHTTP, kept in sync by agents
genhttp-kt is the Kotlin port of GenHTTP, made and maintained by Claude. GenHTTP stays the source of truth, genhttp-kt follows it commit by commit - and the build checks every step mechanically.
- Version
11.1.0.3- Based on
- GenHTTP
11.1.0
GenHTTPupstream
A change lands in the C# repository. A daily check lists what has not been ported yet.
Portagent
An agent ports it - code and tests together, one commit per upstream change, written the Kotlin way.
Verifybuild
Nothing is released unless it holds up.
- 1,000+ tests mirrored 1:1
- Public API compared to upstream
- ABI dumps reviewed
- 90 % line coverage
- Linux, Windows, macOS on x64 and arm64
ReleaseMaven Central
Versions follow GenHTTP: 11.1.0.3 is based on GenHTTP 11.1.0, the last digit counts releases of the port.
The same API, the Kotlin way
Code written for GenHTTP reads the same in genhttp-kt - builders, modules and concepts carry over one to one, expressed with suspend functions, lambdas and data classes.
GenHTTP
var books = new List<Book> { new(1, "Lord of the Rings") };
var api = Inline.Create()
.Get(() => books)
.Get(":id", (int id) => books.FirstOrDefault(b => b.Id == id))
.Post((Book book) => { books.Add(book); return book; });
await Host.Create()
.Handler(api)
.Defaults()
.RunAsync();
public record Book(int Id, string Title);genhttp-kt
val books = mutableListOf(Book(1, "Lord of the Rings"))
val api = Inline.create()
.get { books }
.get(":id") { id: Int -> books.firstOrNull { it.id == id } }
.post { book: Book -> book.also { books.add(it) } }
Host.create()
.handler(api)
.defaults()
.run()
data class Book(val id: Int, val title: String)Pick the framework that fits your application
Every framework runs on the same server and the same modules, so you can mix them within one application.
- Webservices Provide REST based web services in Kotlin that can be consumed by clients to retrieve a JSON, YAML, or XML serialized result.
- Functional Handlers Respond to HTTP requests in a functional manner with Kotlin lambdas and no boilerplate code.
- Controllers Lightweight framework to write web APIs using the controller pattern in Kotlin.
- Websockets Create a simple websocket server in Kotlin on the JVM, with reactive, functional or imperative handlers.
- Single Page Applications (SPA) Simple way to host applications written with JS frameworks such as Vue.js, Angular or React on the JVM with genhttp-kt.
- Static Websites Simple way to host a static website, such as a Hugo site, from a directory or the classpath with genhttp-kt.
- Custom Frameworks Shows how to use the underlying capabilities of genhttp-kt to spin off a custom framework in Kotlin.
Talk to us
Questions, ideas or a project of your own - the community and the team behind GenHTTP are glad to help.