https://kotlinlang.org logo
#http4k
Title
# http4k
a

andyg

08/06/2020, 3:36 PM
Can I ask a philosophical question @dave ? Why do Java/Kotlin http servers like http4k, ktor, vertx also include a client module? There's already mature, full featured, easy to use http clients -- okhttp or fuel or retrofit (a little different, but same idea) for example. Meanwhile Flask doesn't include a client, neither does Laravel or Express. Is it something about the JVM? Is it just because it's easy to rearrange HttpHandlers? Somehow the other day I thought of how different building an http4k server is from a Flask one and was curious why. Thanks.
n

natpryce

08/06/2020, 3:41 PM
It’s very useful to be able to treat services and clients interchangeably. For example in production code, we create a client and pass it to application code as an HttpHandler instance. In tests, we pass in the HttpHandler that implements the service. No actual HTTP involved, so the tests run very fast, and are easy to step through from client application to service in the debugger.
👍 4
But… HTTP4K (and Ktor) don’t implement their own clients. They provide a thin wrapper on top of existing HTTP client libraries. HTTP4K, for example, makes the HTTP client API look like a function.
d

dave

08/06/2020, 3:48 PM
@andyg yep - as Nat mentioned - the uniform model for both servers and clients is a fundamental concept behind the "Server as a Function" model that http4k is based on. it really is incredibly powerful once you've seen it at work at scale. you can have a read of the original paper which might explain more: https://t.co/xv9pj7R0vK
✔️ 3
a

andyg

08/06/2020, 3:50 PM
Yes I read that paper a while ago when I was considering trying out 4k. So that was my thought, as long as you have HttpHandlers it is easy to rearrange and compose various services.
a thin wrapper on top of existing HTTP client libraries
is this something only possible (or very easy) in the JVM? or could someone write a new Python framework for example with 4k's philosophy?
(not planning to do that, just curious)
s

s4nchez

08/06/2020, 4:24 PM
@andyg you can apply the principle in any language. Here’s an example in TypeScript: https://github.com/http4t/http4t
a

andyg

08/06/2020, 4:30 PM
interesting. I know people think JS and Node is cool but I'll stick with Kotlin for writing my server code 🙂 thanks for the info guys, sometimes writing too much code and my mind starts to wander...
d

dave

08/06/2020, 4:47 PM
of course you could 🙃 - there are variants already in scala (which was twitters reference implemention finagle) and typescript (http4t). http4k was overall a mixture of a few other libraries tbh.
2 Views