Fork me on GitHub
#babashka
<
2021-08-28
>
borkdude12:08:45

@grzm and I are working on adding java 11 http client support to bb. In short that will enable you to do requests like:

(ns net
  (:import [java.net.http HttpClient HttpRequest HttpResponse$BodyHandlers]
           [ URI]))

(def req
  (-> (HttpRequest/newBuilder (URI. ""))
      (.GET)
      (.build)))

(def client
  (-> (HttpClient/newBuilder)
      (.build)))

(def resp (.send client req (HttpResponse$BodyHandlers/ofString)))
[(.statusCode resp) (.response resp)]
and offers async, websocket, etc. support. The only trade-off there is: it does add size to the image. Currently about 4.8mb. The question is: is this worth adding compared to the increase in size? We could consider dropping the httpkit client in the future to get some size back (but that one is only about 1mb or so). It will be a breaking change, we will notify users for at least 6 month or so before doing so. After adding support via interop, we could start building some convenience in a babashka.http-client namespace. Please respond in a 🧵 . I might also make a Github discussions topic about it after gathering some feedback here.

borkdude18:08:53

@U3L6TFEJF

$ bb -cp src -e "(require '[java-http-clj.core :as http]) (:status (http/get \"\"))"
200
This is with bb from the jdk-11-http-client branch and with your lib with specs commented out

schmee18:08:18

amazing! 😄

schmee18:08:33

I’ll make a release with the specs moved tomorrow :thumbsup:

borkdude18:08:35

I think the specs will work with spartan.spec but it'd be nice if those can be moved to an optional namespace anyway as this will improve loading time in bb

schmee18:08:53

only one question: would that be considered a breaking change? :thinking_face:

borkdude18:08:09

$ time bb -cp src -e "(require '[java-http-clj.core :as http]) (:status (http/get \"\"))"
200
bb -cp src -e    0.04s  user 0.02s system 65% cpu 0.085 total
Pretty fast too

🎉 2
borkdude18:08:42

@U3L6TFEJF Well, don't remove the specs but move them to, say, java-http-clj.specs

borkdude18:08:52

and then advice people to require that namespace if they want to use those specs

borkdude18:08:00

I don't consider that breaking

borkdude18:08:26

In the future bb will also support clojure.spec but not in its alpha state

schmee18:08:28

that was my plan, I agree that that shouldn’t be a breaking change :thumbsup:

borkdude18:08:57

one thing that your lib has over telex is that it's more minimal so supported in bb more easily. the telex one has more deps on other exoscale deps

schmee19:08:09

excellent, that was one of the goals with the lib and I’m happy to see that it helps facilitate things like use in Babashka 😄

borkdude20:08:22

It does. Would you mind some clj-kondo inspired cleanup? E.g. the Executor class (and some others) aren't really used (and not in bb yet). Commenting out Executor makes it work.

borkdude20:08:34

The websocket.clj namespace can benefit from the same approach

borkdude20:08:43

When I move the specs aside that also loads in bb

borkdude20:08:05

Haven't tested it at runtime though (because I don't know an example of the top of my head)

schmee20:08:54

I’ll take a look! :thumbsup:

borkdude20:08:58

I can also link you to a bb binary for testing, if you let me know your os

schmee20:08:27

branch updated :thumbsup:

schmee20:08:16

note to self: reserve time to play around with clj-kondo 😄

borkdude20:08:34

yep, both work now:

[email protected] /tmp/java-http-clj (separate-spec-ns) $ bb -cp src -e "(require '[java-http-clj.websocket])"
[email protected] /tmp/java-http-clj (separate-spec-ns) $ bb -cp src -e "(require '[java-http-clj.core])"

borkdude20:08:11

@U3L6TFEJF what editor are you using? I can give you some help with that if you want

borkdude20:08:24

also, let me know if you want to test this locally with the work in progress bb

schmee20:08:39

I’m using Vim + Conjure

borkdude20:08:04

Ah I see. neovim by any chance?

borkdude20:08:37

Ah then you're in for a treat with clojure-lsp probably as neovim (0.5.1 or so?) has an lsp client built in

borkdude20:08:52

and clojure-lsp provides nice features like navigation, etc. but also comes with clj-kondo

schmee20:08:32

nice! I have it on my backlog to look into all the nice Neovim 0.5 features but haven’t gotten around to it yet 🙂

schmee20:08:11

great that the lib works now! I’ll do some housekeeping and then push a new release during the day tomorrow :thumbsup:

schmee20:08:30

thanks for your advice and your interest in java-http-clj 😄

borkdude20:08:52

awesome thanks. and when the new bb comes out, we could add a note to the readme of your iib: babashka compatible

borkdude20:08:43

I will add your lib to bb CI as well to ensure it loads also after upgrading

🙏 2
schmee20:08:46

is there an official Babashka badge you can put in READMEs?

borkdude20:08:20

I don't think there is, but that's a cool idea :)

lispyclouds05:08:39

@U3L6TFEJF you can try out my neovim 0.5+ config, all setup for clojure+lsp+conjure and lua powered! 😄 https://github.com/lispyclouds/dotfiles

lispyclouds05:08:43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OTYgNzUzIDQ4Mi4wNTQgNzUzSDQ2OC43Vjc4NC45MThINDc3LjYwM0M0ODUuMTE1IDc4NC45MTggNDkwLjk1NyA3ODcuNjkzIDQ5My40NjEgNzk2LjU3NUw0OTkuMzAzIDgxNy4xMTNMNDQ3IDk1Mkg0ODUuMTE1TDUxNi41NTMgODYzLjE4NUw1MzMuMjQ1IDkxNi43NTJDNTM5LjY0NCA5MzcuNTY4IDU1MC40OTQgOTUyIDU3NC45NzcgOTUySDU5MFoiIGZpbGw9IndoaXRlIi8+CjxkZWZzPgo8bGluZWFyR3JhZGllbnQgaWQ9InBhaW50MF9saW5lYXIiIHgxPSI3NTIiIHkxPSIxMTMiIHgyPSI3NTIiIHkyPSIxMzU5LjUyIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSI+CjxzdG9wIHN0b3AtY29sb3I9IiNFNDFGMjYiLz4KPHN0b3Agb2Zmc2V0PSIxIiBzdG9wLWNvbG9yPSIjQjcwMDAwIi8+CjwvbGluZWFyR3JhZGllbnQ+CjwvZGVmcz4KPC9zdmc+Cg== i put together, hope its a starting point!

Cora (she/her)19:08:06

is clojure.tools.logging.readable something you'd be interested in including in babashka? https://github.com/clojure/tools.logging/blob/master/src/main/clojure/clojure/tools/logging/readable.clj