Skip to content

Instantly share code, notes, and snippets.

@daviddenton
Created August 7, 2019 07:15
Show Gist options
  • Save daviddenton/6c6ca879e96f66779f394ca7a200983b to your computer and use it in GitHub Desktop.
Save daviddenton/6c6ca879e96f66779f394ca7a200983b to your computer and use it in GitHub Desktop.
import org.http4k.client.ApacheClient
import org.http4k.core.HttpHandler
import org.http4k.core.Method.POST
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() {
val app: HttpHandler = { req: Request ->
println("HEADER WAS: " + req.header("foobar"))
Response(OK).body(req.body.stream)
}
val server = app.asServer(Jetty(10000)).start()
val request = Request(POST, "http://localhost:10000")
.header("foobar", "headervalue")
.body("hello".byteInputStream())
println("Response was: " + ApacheClient()(request).bodyString())
server.stop()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment