Server backend

Installation (Gradle)

dependencies {
    implementation(platform("org.http4k:http4k-bom:5.21.1.0"))
    // Apache v5: 
    implementation("org.http4k:http4k-server-apache")

    // Apache v4: 
    implementation("org.http4k:http4k-server-apache4")

    // Jetty & JettyLoom: 
    implementation("org.http4k:http4k-server-jetty")

    // Helidon (Loom): 
    implementation("org.http4k:http4k-server-helidon")

    // Ktor CIO: 
    implementation("org.http4k:http4k-server-ktorcio")

    // Ktor Netty: 
    implementation("org.http4k:http4k-server-ktornetty")

    // Netty: 
    implementation("org.http4k:http4k-server-netty")

    // Ratpack: 
    implementation("org.http4k:http4k-server-ratpack")

    // Undertow: 
    implementation("org.http4k:http4k-server-undertow")

    // Java WebSocket:
    implementation("org.http4k:http4k-server-websocket")

    // SunHttp & SunHttpLoom (for development only): 
    implementation("org.http4k:http4k-core")
}

About

Server-backend modules provide a consistent API to mount HttpHandlers into the specified container in 1 LOC, by simply passing it to the relevant ServerConfig implementation (in this case Jetty):

Code

package guide.reference.servers

import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.server.Jetty
import org.http4k.server.asServer

fun main() {
    { _: Request -> Response(OK).body("Hello World") }.asServer(Jetty(8000)).start()
}

Customisation

Each of the server backends implement an interface ServerConfig, which is written with sensible defaults for the server in questions, but is also designed to be used as a starting point for tweaking to API user needs. To customize, simply use the relevant ServerConfig class as a starting point and reimplement as required. See the how-to guides for an example of this in use.