Hato - An HTTP client wrapping JDK 11's HttpClient

Hi all,

There has been a bit of interest in the JDK 11 HttpClient so I have built a small wrapper to make it more accessible.

Please check out hato and see what you think.

It supports both HTTP/1.1 and HTTP/2, with synchronous and asynchronous execution modes.

The main features yet to be implemented are:

  • multipart requests
  • custom middleware
  • web socket client

I have tried to make the documentation quite comprehensive, and the API should be mostly stable leading up to 1.0.0. I am still pondering over things like how much input validation/exception handling to do to hide the java internals and would appreciate any thoughts in this area.

A lot of credit goes to other libraries in this area such as clj-http and aleph, from which much of the implementation was sourced.

6 Likes

Hey… is Hato Ring compliant?

1 Like

What does it mean for an HTTP client to be “Ring-compliant”?

It should be exposed via the Ring spec: https://github.com/ring-clojure/ring/blob/master/SPEC

Aleph does this, so it’s a drop in replacement. Same for clj-http I believe. It wraps Apache HttpClient in a Ring compatible way.

I can understand an HTTP server being (or not being) Ring-compliant. Not sure how that applies to a client – which is for making HTTP calls, not for responding to them.

Yes, Aleph is a drop-in replacement for a Ring server. http-kit’s server code is also (almost) a drop-in replacement for a Ring server.

Not sure how clj-http can be a drop-in replacement for a Ring server…?

Oh :man_facepalming:

This whole time I thought JDK 11 had brought a new standard modern HttpServer with HTTP 2 support as part of the standard library.

Ya, for an HttpClient :yum: it doesn’t make as much sense. Though I guess, if it adhered to Ring’s request and response map specs you could call it Ring compliant: https://github.com/ring-clojure/ring-spec/blob/master/src/ring/core/spec.clj#L114

But ya, I goofed though. Totally thought this was a server, even though I even wrote client on my previous post, and really I was thinking clj-http wrapped the Apache server :weary:

Now that my brain caught up with it being a client, it looks very nice!

1 Like

:slight_smile: hato accepts a superset of the ring request options and returns a superset of the ring response attributes.

That said, typically a user would interact via higher level options (e.g a single url instead of protocol/hostname/port/path/query-string), and the default middleware stack will coerce those options into a ring request before turning it into a Java HttpRequest.

In terms of drop-in replacement, hato, like the aleph client, aims to be very similar to clj-http, and so most request options will just work. The client options are slightly different due to the different underlying implementation but for the most part should be a trivial change.

1 Like

It seems pretty nice especially to keep dependencies low! I’ll give it a shot soon considering that I write a lot of client code to retrieve data :wink:

Seems like we wrote the same library! :grin: https://github.com/schmee/java-http-clj

Seems like you opted to stick closer to clj-http, while I decided to create a different API. More options is rarely a bad thing! :grinning:

5 Likes

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