Client as a function

This example demonstrates using http4k as a client, to consume HTTP services. A client is just another HttpHandler.

Gradle setup

implementation group: "org.http4k", name: "http4k-core", version: "3.269.0"

Code

package cookbook.client_as_a_function

import org.http4k.client.JavaHttpClient
import org.http4k.core.HttpHandler
import org.http4k.core.Method
import org.http4k.core.Request

fun main() {

    val request = Request(Method.GET, "https://xkcd.com/info.0.json")

    val client: HttpHandler = JavaHttpClient()

    println(client(request))
}