Skip to content

Instantly share code, notes, and snippets.

@s4nchez
Created October 29, 2023 09:00
Show Gist options
  • Save s4nchez/770f54d153cc9f2e01e3f93fc526744f to your computer and use it in GitHub Desktop.
Save s4nchez/770f54d153cc9f2e01e3f93fc526744f to your computer and use it in GitHub Desktop.
Example of http4k server and client
import org.http4k.client.JavaHttpClient
import org.http4k.core.Method
import org.http4k.core.Request
import org.http4k.core.then
import org.http4k.filter.DebuggingFilters.PrintResponse
fun main() {
val client = JavaHttpClient()
val printingClient = PrintResponse().then(client)
printingClient(Request(Method.GET, "http://localhost:9000/ping"))
}
import org.http4k.core.Request
import org.http4k.core.Response
import org.http4k.core.Status.Companion.OK
import org.http4k.server.SunHttp
import org.http4k.server.asServer
fun main() {
val server = { _: Request -> Response(OK).body("pong") }
server.asServer(SunHttp(9000)).start()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment