HTTP client and server considerations - babashka/babashka GitHub Wiki

EDIT 2023:

https://github.com/babashka/http-client will be the recommended http client in babashka which solves all of the below issues. It will be included as a built-in.

HTTP client considerations

Currently babashka exposes http-kit's client. Http-kit seems like a good fit for a scripting utility like babashka, so for now we're good. There may be reasons to move away to alternatives in the future:

  • http-kit becomes too far behind on current tech like HTTP2. Curl (accessible via babashka.curl) supports http2 though.
  • http-kit's inability to stream without holding everything in memory becomes a problem. Babashka.curl may offer a good alternative for downloading big files.
  • babashka.curl shells out to curl and sometimes having an OS process per request is too much overhead. Also on Windows it causes issues if the default curl isn't up to date.

Binary size

Http-kit has the best binary size of all client+servers tested so far. It only adds 1.3MB to the size of babashka for both the server and client. The branch java-11-client-and-jetty has a Java 11 http client and Ring core + Jetty adapter. This adds 4.8MB in total.

HTTP2 support

Httpkit doesn't have http2 support. Ring jetty also doesn't have this but can support it in the future. The Java 11 client does have HTTP2 support.

Websocket support

Httpkit offers websocket support. Ring jetty does not have this built-in. Portal uses the websocket support from httpkit at the moment. Also see https://github.com/sunng87/ring-jetty9-adapter.

Java 11 client

Java 11 client. Based on https://github.com/schmee/java-http-clj minus the specs. Adds 2.28MB to the binary. See branch java-11-client. Another client: telex.

Ring jetty

See https://github.com/BrunoBonacci/graalvm-clojure/tree/master/ring-jetty and branch java-11-client-and-jetty Adds 2.92MB to the binary.

Http-kit holds entire request/responses in memory

Conversation on Slack: borkdude I'm slightly worried that with org.httpkit.client some people will run into the issues that it consumes the entire request / response into memory. I hadn't seen those issues before I added it and people were mostly positive about httpkit. Maybe people don't do huge requests mostly? New 10:58 PM rwstauner yeah, for small use cases it's super handy and IMO if you build something big enough that it needs to be optimized you could probably stand to make a clojure project out of it 10:59 PM your image_viewer example is absurdly handy 10:59 PM lukasz +1, I'm using it to get JSON payloads from servers, I wouldn't use it to process files etc - we have "big" Clojure for that 11:03 PM borkdude makes sense. also big files you can do with babashka.curl as well which won't hold it in memory at once when streaming