I have a branch http-kit-client
now in which I added the http-kit-client.
$ ./bb '(:status @(org.httpkit.client/get "<https://www.google.com>"))'
200
Only a 0.7MB increase for an http client. That doesn't seem too bad!I didn't get SNI working. When I did what the README said, I got a NPE:
$ clojure -A:bb-local "@(org.httpkit.client/get \"<https://www.google.com>\")"
{:opts {:method :get, :url "<https://www.google.com>"}, :error #error {
:cause nil
:via
[{:type java.lang.NullPointerException
:message nil
:at [sun.net.util.IPAddressUtil textToNumericFormatV4 "IPAddressUtil.java" 49]}]
Maybe @alekcz360 knows a proper solution to this?
There are binaries in #babashka_circleci_builds for trying this out btw.
I guess error handling with http-kit works by checking manually for :error
?
@borkdude how do I include the SNI client? in bb
./bb "(require '[org.httpkit.sni-client :as sni-client])
(require '[org.httpkit.client :as client])
(:status (binding [org.httpkit.client/*default-client* sni-client/default-client]
@(client/get \"<https://www.google.com>\")))"
Thanks @borkdude for creating a great tool! https://www.karimarttila.fi/clojure/2020/09/01/using-clojure-in-command-line-with-babashka.html
Thanks 🙏 I shared the article on Twitter. On the libraries page there is also a library for psql. Also we have a pod so you can directly use jdbc.next and honeysql with Postgres
Ok. Good to know. I'll use the library support for sql next time!
At one point I had the JDBC driver for PostgreSQL included in babashka, so you could use next.jdbc directly from babashka, but I wasn't sure if this was the right approach, since I maybe would have also include drivers for other databases and this would maybe bloat babashka. But it is still possible to compile babashka with postgres support using a feature flag as well. So, several options. But your basic approach is also valid, whatever works :)
@alekcz360 That's already been done in babashka.impl.http_kit.clj
At least, I tried, but it only works with JDK 1.8
Awesome! I'm going to read through it tonight when I'm back at the keyboard!
@alekcz360 https://github.com/borkdude/babashka/blob/5a28a8ac51808cfeb11be5e0a7174bd3d3cf8852/src/babashka/impl/http_kit.clj#L8
@alekcz360 You can run this locally from the bb repo as follows:
clojure -m babashka.main "@(org.httpkit.client/get \"<https://www.google.com>\")"
without compiling first
afk for a while now
@borkdude It worked when running locally. I'll investigate more tomorrow. Going afk for the evening.
Yes, note that it works as is, but not when you uncomment the alter-var-root line :)
Ah, it does work when I set JAVA_HOME to GraalVM 11!
but just not with AdoptOpenJDK 11
Upgrading to AdoptOpenJDK 11.0.8 worked! https://github.com/http-kit/http-kit/issues/440
I now fully read your blog. Very nice! Babashka does offer some libraries in addition to what is built-in: https://github.com/borkdude/babashka/blob/master/doc/libraries.md
I updated the README a bit: https://github.com/borkdude/babashka#built-in-namespaces
But I do get your point: Python has a much bigger library ecosystem, no argument there :)
Thanks for your nice blog. Are you going to share it anywhere? Reddit / Twitter, etc?
This is pretty awesome. Inspect a big chunk of edn using clojure.datafy, bb and portal:
$ cat deps.edn | bb -cp `clj -Spath -Sdeps '{:deps {djblue/portal {:mvn/version "RELEASE"}}}'` -m portal.main edn
Sure. Happy to share the awesome stuff you and @djblue have made 🙂
To be honest I hadn't used clojure.datafy that much myself, but I'm mind blown now ;)
Related to datafy, do you know if the pod edn format preserves metadata? I tried some of the https://github.com/babashka/babashka-sql-pods examples but wasn’t seeing any of the metadata next-jdbc puts on its results for datafy
Hmmmmm
I wasn't aware of the metadata on that and I think you need to turn this on explicitly, it's probably not currently
Even if there is metadata support, not sure this would work because the metadata it puts on are protocol fns
yeah, I think this doesn't work with pods probably
well maybe we could make it work
a pod can also define client side functions
Example metadata:
#:clojure.core.protocols{datafy #object[next.jdbc.result_set$navize_row$fn__17145 0x4c1ea0ab "next.jdbc.result_set$navize_row$fn__17145@4c1ea0ab"]}
oh functions
we could hack around that by representing the function using a name, but if it's a closure then that won't work
ah yep
can you point me to the place where next.jdbc attaches that metadata?
if everything was in babashka itself, it would work. I'm partial about including only postgres, but we could
it's still available behind a feature flag
if you compile bb on your own system
https://github.com/seancorfield/next-jdbc/blob/97332c1a1a7f7b630d9909ff05fe8928cc644d62/src/next/jdbc/datafy.clj#L126-L152 is one place where datafy support is added
Forgot about the feature flag. I’ll try that 🙂 I’m definitely not advocating for bloating bb core. It is interesting to see where pod’s limitations are
I'm very tempted to add postgres support, since it's so cool ;)
ah yeah, so it's a closure over this
What am I missing? It is a library right? So I don't have to install a pod, correct?
cat deps.edn | bb -cp
clojure -Spath -Sdeps '{:deps {djblue/portal {:mvn/version "RELEASE"}}}'` -m portal.main edn`
clojure.lang.ExceptionInfo: Could not resolve symbol: realized? [at portal/http_socket_server.clj, line 65, column 20]
@mmz Are you using bb 0.2.0?
That one is required
let me check ... bb -v
?
$ bb --version
babashka v0.2.0
Works now! (did a brew update
before testing ... should have done a brew upgrade babashka
:face_palm::skin-tone-3: )
This is indeed pretty awesome! :thumbsup::skin-tone-3:
Also works for json or transit. Thanks for sharing @cldwalker