Depending on your learning style, there are a number of options to get started with http4k...

I'm starting from scratch

Follow a tutorial: There is a step-by-step beginner tutorial. This will get you up and running with a basic buildable project.

I'd like a helping hand

Generate a new project with the http4k Toolbox: We have developed a set of useful tools for Developers working with the http4k toolset to turbo-charge app development. Collectively, this is known as the http4k Toolbox. These tools include:

  • A Project Wizard that generates entire bootstrap Server and Serverless project source folders - including fully working starter code, build tooling, extra modules and packaging options.
  • From OpenAPI v2 & V3 specification JSON/YAML, generate an entire working http4k Server, Client and Model objects (generated from JSON Schema).
  • Generate Kotlin Data Class definitions from an inputted JSON, YAML, or XML document.

I'm already set up and just need to integrate!

Add http4k into an existing project: This simple example demonstrates how to serve and consume HTTP services using http4k. To install, add these dependencies to your Gradle file:

dependencies {
    implementation(platform("org.http4k:http4k-bom:5.14.4.0"))
    implementation("org.http4k:http4k-core")
    implementation("org.http4k:http4k-server-undertow")
    implementation("org.http4k:http4k-client-apache")
}

The following creates a simple endpoint, binds it to a Undertow server then starts, queries, and stops it.

package quickstart

import org.http4k.client.ApacheClient
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.server.Undertow
import org.http4k.server.asServer

fun main() {
    val app = { request: Request -> Response(OK).body("Hello, ${request.query("name")}!") }

    val server = app.asServer(Undertow(9000)).start()

    val client = ApacheClient()

    val request = Request(Method.GET, "http://localhost:9000").query("name", "John Doe")

    println(client(request))

    server.stop()
}

I want to see what http4k can do!

See how it's done in the Examples Repo: For fully self-contained examples demonstrates the standout features of http4k, there is a GitHub repository at http4k/examples.