HTTP/2 Client


I’m interested in putting together a small app which would require an HTTP/2 client. There are a lot of references to HTTP/2 servers around, but http-kit and clj-http both appear to provide HTTP/1.1 clients.

Is anyone aware of an option I’ve missed?

ClojureScript and run Node.js HTTPS server?

Unfortunately I’m not seeking a server, just a client.

This? it runs in both browsers and Node.js.

If you are running Clojure on Java11 you can use the newly added HttpClient which has full support for HTTP/2. The API is a bit java-ish but works well enough from Clojure.

(ns foo.test
  (:import [ HttpClient HttpRequest HttpClient$Version HttpResponse$BodyHandlers]
           [ URI]))

(let [req
      (-> (HttpRequest/newBuilder)
          (.uri (URI/create ""))

      (-> (HttpClient/newBuilder)
          (.version HttpClient$Version/HTTP_2)

      (.send client req (HttpResponse$BodyHandlers/ofString))]
  (println (.body res)))

The entire package is pretty powerful and supports everything you’ll ever need to do HTTP requests. Assuming of course you are running Java11 and Clojure.


Thanks all!

I haven’t spent much time in Java but thheller’s advise looks like the resolution.

And horribly verbose though. Yes, you can abstract over this but then you realized you are spending 70% writing interop abstractions instead of business logic. Of course, this is a case where the libs I need are available in Java but not Clojure.

Writing these for clojure beginners to make them aware that the phrase “You can leverage all the Java ecosystem” is not all roses.

Yes, the API doesn’t look like Clojure. For a Java API it is pretty clean and the point is that you do NOT need to abstract it in any way. You can use it directly. The whole point of Clojure is to “embrace the host” and not reinvent everything just because.

Given how “new” Java11 is and how many people are still on Java8 I’d expect a Clojure wrapper for at some point. Clojure devs that don’t know Java may be more comfortable with that and that is fine.

HTTP requests can be an incredibly complex subject if you want to do them at scale (thousands, millions, …). Many client libs choose to hide some of the complexities and simplify or compromise in certain situations and that is fine too. Use the right tool for the job …

Was one of the major selling points of Clojure to me. The majority and Clojure beginners also still come from Java (see Q3 in the recent survey results). YMMV.


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.