Server backend

Installation (Gradle)

// Apache v5: 
implementation group: "org.http4k", name: "http4k-server-apache", version: "3.280.0"

// Apache v4: 
implementation group: "org.http4k", name: "http4k-server-apache4", version: "3.280.0"

// Jetty: 
implementation group: "org.http4k", name: "http4k-server-jetty", version: "3.280.0"

// Ktor CIO: 
implementation group: "org.http4k", name: "http4k-server-ktorcio", version: "3.280.0"

// Ktor Netty: 
implementation group: "org.http4k", name: "http4k-server-ktornetty", version: "3.280.0"

// Netty: 
implementation group: "org.http4k", name: "http4k-server-netty", version: "3.280.0"

// Ratpack: 
implementation group: "org.http4k", name: "http4k-server-ratpack", version: "3.280.0"

// Undertow: 
implementation group: "org.http4k", name: "http4k-server-undertow", version: "3.280.0"

// SunHttp (for development only): 
implementation group: "org.http4k", name: "http4k-core", version: "3.280.0"

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.modules.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: 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 Cookbook for an example of this in use.