Fork me on GitHub
#babashka
<
2023-08-29
>
mmer09:08:07

Hi Is there a reason for the clj-http.lite.client does not implement the patch option?

borkdude09:08:06

yes, I think it's a JVM limitation. Why don't you use babashka.http-client which uses java.net.http which is more modern?

mmer09:08:33

Partly because of handling :insecure. I don't see any examples in the docs and when I look in the api I find it difficult to understand what I am supposed to do with the API calls, where the lite client is obvious.

mmer09:08:01

I think I am correct that I need to create a client first and then make the call, but I don't see this in the docs.

mmer09:08:39

I thought the call below would give me the insecure call but it does not:

(ns example.core
  (:require [babashka.http-client :as httpc]))

(httpc/request 
               {:uri url
                :method :patch
                :ssl-context (httpc/->SSLContext :insecure)
                :body content
                :accept :json
                :headers {"Version" version}
                :content-type :json
                :oauth-token token
                :throw-entire-message? true}

borkdude09:08:42

@U4C3ZU6KX Why didn't you just ask? I updated the docs to make that part clearer: https://github.com/babashka/http-client#custom-client

borkdude09:08:45

This isn't correct:

(httpc/->SSLContext :insecure)
You need to pass a map:
(httpc/->SSLContext {:insecure true})

borkdude09:08:53

and also this isn't a request option, but a client option

mmer09:08:12

Ok sorry for misunderstanding.

mmer09:08:21

Thanks for pointing me to the docs.

borkdude09:08:47

If anything is still unclear, let me know

borkdude09:08:32

:accept :json also isn't an option in babashka.http-client, you need to write {:headers {:accept "application/json"}}

borkdude09:08:42

just read the docs and don't use anything by just guessing

mmer09:08:16

Agreed, was so used to using clj-http from other projects prior to moving to bb.

borkdude09:08:52

it could be that the docs are lacking though

mmer10:08:45

Sorry to keep asking - how does oauth 2 work with the http-client. I can only see basic auth in the docs, unless I am missing something

borkdude10:08:23

http request are basically nothing but sending data like a body and headers. oauth2 is not something that happens on the level of http requests, but rather, is built on top of that

mmer10:08:00

So are you saying you just have to write the correct data into the headers?

mmer10:08:31

Yes so just had a {:oauth token}

borkdude10:08:41

Just send this header:

Authorization: Bearer <token>

mmer10:08:09

Thanks, Sometimes the libraries look after you to the point that you don't have to think about the underlying functionality. Now I understand that the babashka.http is not that way I am happy.

joost-diepenmaat10:08:26

Hi everybody. A quick report of my problems trying to install babashka from the release zip on a (slow, annoying) windows vm. A few unexpected hiccups: • MS Edge on my VM can’t open the list of files in github releases pages. Also doesn’t scroll to the #installing anchor on the babashka README in github. Fixed by installing firefox. 😕 Not really a babashka issue but still surprising given that github is owned by Microsoft. • Apparently bb.exe needs VCRUNTIME140_1.dll which is in something called “https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170” and can be downloaded from the very respectable looking url • Then, running a babashka project with deps fails with Exception in thread "main" java.lang.Exception: Couldn't find 'java'. Please set JAVA_HOME. I did not expect that I needed to have Java installed in order to run babashka. Maybe something weird with my dependencies or is this expected behaviour? https://gist.github.com/joodie/6eb06be4d39e7ab5ddc48cc677714243

borkdude10:08:29

Can you please limit the output of your message to a gist or so to not flood this channel?

borkdude10:08:58

After that I'll start answering your questions

borkdude10:08:59

Yes, graalvm binaries rely on the c++ redistributable. This is very common for Windows programs

borkdude10:08:48

Babashka uses Java for fetching dependencies. If you have any dependencies in bb.edn then it will invoke https://github.com/borkdude/deps.clj (which uses #tools-deps) to fetch them

joost-diepenmaat10:08:42

Ah ok, so if I have the dependencies available locally it should not need Java? I’m trying to create a project with a few CLI commands + configuration and I want it to be as easy to use as possible. Target audience is technically minded people / developers who don’t necessarily have or want any Java or Clojure experience. Maybe I should look into https://github.com/babashka/babashka/wiki/Self-contained-executable

borkdude10:08:47

You can produce an uberjar from your CLI and then install it via #C0400TZENE7. This should not require a JVM

borkdude10:08:26

bb uberjar foo.jar -m foo.bar/-main

borkdude10:08:43

then upload your uberjar to github releases and just point bbin to it

borkdude10:08:21

e.g.:

bbin install 

joost-diepenmaat10:08:13

Oh that’s pretty nice. Does bbin require babashka or is that included in the installation?

borkdude10:08:39

yes, bbin requires babashka

borkdude10:08:02

I'd recommend Windows users to use scoop.

scoop bucket add scoop-clojure 
scoop install bbin

borkdude10:08:13

this is similar to brew

👍 4
DeepReef1115:08:53

How to get length of string with babashka? This won,t work: (count "a b c") I get this message: java.lang.Long cannot be cast to clojure.lang.IFn

2
chucklehead15:08:29

Do you have an extra pair of parentheses around that maybe?

Bob B15:08:38

$ bb -e '(count "a b c")'
5
is it possible that in context the result is being called?

DeepReef1115:08:41

I have (count "abc") in a try statement just to test out and it doesn,t work. There's no extra ()

Bob B15:08:18

can you provide the actual code (or a minimal repro)?

DeepReef1115:08:33

(try
                      (let [
                            s "maximum printing width for this tape is "
                            ]
                        (count "a b r")
                        )
                      (catch Exception e (println (str (.getMessage e) "..")))

Bob B15:08:12

might be missing a closing paren

(try
  (let [s "maximum printing width for this tape is "]
    (count "a b r"))
  (catch Exception e (println (str (.getMessage e) ".."))))
=> 5

DeepReef1115:08:34

I think I found. Seems like using clojure.core/count works for some reason

chucklehead15:08:07

do you redefine count somewhere prior to this code?

2
Bob B15:08:24

might want to eval count in the REPL and see what comes back

DeepReef1115:08:11

Yes this was it! I named a variable count... that was a bad idea

DeepReef1115:08:41

Thanks a lot

pesterhazy16:08:34

Shadows are an unfortunate but frequent source of confusion.