Skip to content

Server backend

Installation (Gradle)

Apache v5: compile group: "org.http4k", name: "http4k-server-apache", version: "3.251.0"

Apache v4: compile group: "org.http4k", name: "http4k-server-apache4", version: "3.251.0"

Jetty: compile group: "org.http4k", name: "http4k-server-jetty", version: "3.251.0"

Ktor CIO: compile group: "org.http4k", name: "http4k-server-ktorcio", version: "3.251.0"

Ktor Netty: compile group: "org.http4k", name: "http4k-server-ktornetty", version: "3.251.0"

Netty: compile group: "org.http4k", name: "http4k-server-netty", version: "3.251.0"

Ratpack: compile group: "org.http4k", name: "http4k-server-ratpack", version: "3.251.0"

Undertow: compile group: "org.http4k", name: "http4k-server-undertow", version: "3.251.0"

SunHttp (for development only): compile group: "org.http4k", name: "http4k-core", version: "3.251.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.