Fork me on GitHub

I've just started looking at and I'm using it with holy-lambda in an aws lambda and I'm very unclear how I'm supposed to do a http get / post? There does seem to be a http-client inside the pod's source, but when I try and require it, it's not there. How exactly am I supposed to make http requests to other services etc?


How would you do that with cognitect aws api?


You can also try which works from source


Sorry, I suppose the question is a bit wider, where is the http client in babashka then? Is it inside the client? I've seen references to curl, but I'm not sure I should be calling on curl in a lambda context?


I'm using it for the first time to do some lambda development, so I'm still unfamiliar with the environment 😃


@U0JUM502E Ah right. For http you have the following options:


- babashka.curl
- org.httpkit.client
or a wrapper for like


Calling curl from a lambda context, not sure if it works, but you have the other options as well


So for example, I just add:

java-http-clj/java-http-clj {:mvn/version "0.4.3"}
in my deps.edn, and then I should be able to require it at my repl?


you add it to bb.edn


which is similar to deps.edn in this regard


So what's the relationship between them, there are some examples where they suggest putting it in deps.edn, are they independent?


bb does not read from deps.edn by default


there might be outdated examples - if you can point me to those, please let me know


I don't know if they're ones you control or if it's just using a different paradigm, for example this was super confusing. I assume it works some other way...


Ok, that seems to be working 😃... Not sure if it's going to break when it comes time to deploy it, which is what I'll test next! Thanks for your help @U04V15CAJ 😃...


Sure! Let me know if you have any further questions :)

Karol Wójcik15:06:27

@U0JUM502E this is example of using cognitect AWS API with native backend whereas you’re using babashka one ;D


Makes sense, thanks


@U04V15CAJ, just trying out clj-http instead and I'm getting this:

(require '[clj-http.client :as client])
: Unable to resolve classname: org.apache.commons.codec.binary.Base64 humble-aws-fn.core 


I've added imports, but it seems to not be picking it up? Basically I need form handling for the http client, so I can send forms, which java-http-clj doesn't appear to cover?


What's form handling?


Can you give an example?


Sure, for example:

(http/post ""
  {:headers {"ContentType" "application/json"}
   :body {"id" 1234567 "data" {"a" "a"}}})
Take this, what I have to work with is :body, so if I want to send a raw json body, that's fine, I just call cheshire.core/generate-string on the value at :body, but to send form encoded? That's a bunch more complex. So normally this falls under stuff I expect the http client lib to handle, but in this case it doesn't, so I'm just wondering is there a more fully featured client, for example clj-http


@U0JUM502E Ah right. I think for this to work you just have to do something like this:

(require '[clojure.string :as str])
(defn encode [v] ( v))
(defn encode-map [m] (str/join "&" (reduce-kv (fn [acc k v] (conj acc (str k "=" (encode v)))) [] m)) )
(encode-map {"a" "1" "b" "foobar$123"}) ;;=> "a=1&b=foobar%24123"


But I think it's reasonable if java-http-clj would do this for you with the given content type. What do you think @U3L6TFEJF?


Hmm, ok, that should work I think but there's the server isn't accepting it, so there's some gap. I'm going to try and work out what...


Cool. Maybe you can also use hato which is closest to clj-http


I'll be back in an hour after dinner. For hato you need to add babashka spec alpha to your bb edn I think too


Ok, this seems to work now


I didn't realise the form encoding step could be done that easily, I remember having to setup some object and do some setting etc when I was in jsland. Giving hato a look


Hmm, not sure how to use it, after I added it to bb.edn. When required it I got Could not find namespace: clojure.spec.alpha adding clojure.spec.alpha to bb.edn and deps.edn didn't seem to help. EDIT: Ahh, just spotted the message about a special version of spec alpha


@U0JUM502E Add this to your bb.edn:

org.babashka/spec.alpha {:git/url ""
                         :git/sha "1a841c4cc1d4f6dab7505a98ed2d532dd9d56b78"}
You can also try the built-in client org.httpkit.client:
(require '[org.httpkit.client :as client])
@(client/post "" {:form-params {"a" "foo bar"}})


Oh, I didn't realise there was a builtin 😃


Yeah, it's :) So we have three options in bb: • bb.curl • httpkit client •


And even a fourth one: HttpUrlConnection and clj-http-lite which is based on that (external library)

😅 1

That's a fair bit of choice


Really liking Babashka's synergy with Bash and Unix. Long lines, best viewed with wide slack.

🎉 1

A PR to make bb compatible with #malli Instructions on how to try it now are in the PR!

🙌 4