http4k
By http4k community
http4k is an open-source Kotlin toolkit for building HTTP applications — servers, clients, and proxies — using plain functions that map an HTTP request to an HTTP response. It has no required annotations, reflection, or external runtime…
Definition
http4k is an open-source Kotlin toolkit for building HTTP applications — servers, clients, and proxies — using plain functions that map an HTTP request to an HTTP response. It has no required annotations, reflection, or external runtime dependencies beyond Kotlin itself, and treats server backends and HTTP clients as interchangeable implementations of the same core function type, which makes applications easy to test without a running server.
Overview
http4k was designed around a single, uncommonly literal idea for a web framework: an HTTP application is just a function from a request to a response. Where most web frameworks tie route handlers to annotations, dependency injection containers, or framework-specific request objects, http4k models an HTTP handler as a plain Kotlin function type, `HttpHandler`, which takes a Request and returns a Response, and everything else in the toolkit — routing, filters, server backends, clients — is built by composing functions of that same shape. Mechanically, routes are declared by matching a path and method to a handler function, and multiple routes are combined into a single routing HttpHandler using simple composition operators. Filters, which wrap a handler to add cross-cutting behavior like logging or authentication, are themselves just functions that take a handler and return a new handler, so the entire request pipeline is built from ordinary function composition rather than a framework-specific middleware or interceptor abstraction. Because the server backend (Jetty, Netty, Undertow, or others via pluggable modules) is just another implementation of the same handler contract, an application can run against any of them without changing its own code, and tests can call the handler function directly without starting a real server or network socket. Compared to frameworks like Spring MVC or Ktor, http4k deliberately avoids reflection, annotation processing, and a dependency injection container, favoring explicit function composition and constructor-based wiring instead. This trades some of the convenience and ecosystem size those frameworks offer for a design that is easier to reason about, test, and refactor with the compiler's help, since almost everything is a typed function rather than framework-managed magic. In practice, http4k is used by teams that value pure functional composition and fast, in-memory testing of HTTP logic, often in domains like finance where correctness and testability weigh heavily. Its contract testing feature, which lets client and server implementations be tested against a shared specification, is a particular draw for teams building internal APIs consumed by multiple services. http4k's minimalist, function-first philosophy means it has a smaller ecosystem of plugins, less built-in convention (such as automatic serialization wiring) than Spring Boot, and a learning curve for developers used to annotation-driven frameworks who need to adjust to composing functions explicitly. Teams that value convention-over-configuration and a very large plugin ecosystem, with abundant tutorials, sample projects, and third-party integrations already written for them, may find Spring Boot or Ktor a more familiar and immediately productive fit.
Key Features
- Models an HTTP application as a plain function from request to response
- No annotations, reflection, or dependency injection container required
- Pluggable server backends including Jetty, Netty, and Undertow
- Filters compose cross-cutting behavior as functions wrapping handlers
- Handlers callable directly in tests without starting a real server
- Built-in contract testing to verify client and server compatibility
- Typed routing DSL for matching paths and methods to handlers
- Small, dependency-light core library