http-kit: Consider "easy" sync interface which does error handling for you, like clj-http?

I’m considering to adopt http-kit client in babashka so it can be used for scripting.

One thing that’s different in http-kit vs clj-http is that when used synchronously, you have to check for :error and/or :status and then throw yourself (or do some other handling). But this requires writing a bunch of boilerplate. I reckon every httpkit user has their own boilerplate for this.

That’s why I’m also considering adding a synchronous interface over httpkit, in a namespace called babashka.http-client which does deref for you, if there’s an :error, it will throw the error and it will also throw on a selection on status codes, like clj-http does, unless :throw is false. Is something like this maybe considered for httpkit proper?

If babashka users want the async httpkit, they can just use the existing http-kit namespaces.

I’m also considering to enable the SNI client by default, so that boilerplate isn’t needed either.

Please let me know if I’m overlooking something, I’ve only recently started looking at httpkit. I usually just want my script to exit with an error in case of a faulty request.

See https://github.com/borkdude/babashka/issues/561

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 16 (5 by maintainers)

Most upvoted comments

I think the conclusion of this issue reads: from http-kit’s perspective there isn’t a need for an “easy” “clj-http”-like interface, but from babashka there is. Therefore I will implement on babashka’s side as babashka.http.client (or babashka.http-client, the bikeshed jury is still out on that).

Btw, the above binaries also contain org.httpkit.server: run a web server which starts in milliseconds 😃

FWIW, my current take on this is the following:

  • babashka.curl will be the easy (possibly less performant, because shelling out to curl) way of doing http requests
  • org.httpkit.client will be the performant, async, configurable, more low level, in-process way of doing http requests

So users have a choice to use either and there’s no need for wrapping anything.

The client is now part of these binaries:

Will release a new version probably this week.

About the above issue:

I found that clj-http behaves the same:

user=> (require '[clj-http.client :as c1])
nil
user=> (:body (c1/get "https://httpstat.us/200"))
""

We can probably dismiss that as a weird edge case.