Fork me on GitHub
Ahmed Hassan08:08:05

how can i clj-http.client/post with :body-params?

Ahmed Hassan08:08:39

because docs only mention :form-params and :query-params.


my understanding is that :form-params is basically :body-params

Ahmed Hassan08:08:29

When I print request on server it includes :form-params under :params and :form-params keys.

Ahmed Hassan08:08:30

I need params under :body-params key.

Ahmed Hassan08:08:33

Basically I'm using which sends :post params under :body-params key. So, all handlers at server extract :body-params from request.

Ahmed Hassan08:08:16

I want to do similar :post requests with clj-http.client/post, to inspect routes from REPL.


@ahmed1hsn I usually don't use a HTTP-client to test routes from REPL. If your backend is Ring compatible (which it probably is) you can call the handler function directly and pass a request map created with

👍 1
Ahmed Hassan11:08:05

handlers are wrapped anonymous functions inside integrant init-key multimethod.

Ahmed Hassan13:08:57

I don't know how can I find reference to handler to run ring-mock


How are you defining your handlers? Which library are you using?

Ahmed Hassan14:08:39

I'm using duct with Ataraxy as routing lib.


Ok I don’t have experience with them so it’s hard to help without seeing the code.


But if you want to use clj-http you should probably put the body under :body, as in the first example at

👍 1
Ahmed Hassan12:08:10

Thanks it works, but I have to escape double quotes with slashes.


Yes, body is expecting a string. You probably want to use a library to convert whatever data structure you have to string. For example cheshire or jsonista if you're using JSON for communication. If you're using EDN you can just use pr-str.

👍 1

user> (pr-str {:a 2 :b "kissa"})
"{:a 2, :b \"kissa\"}"

👍 1

is it useful to use pmap in the middle of a ->> or -> processing pipelines? I could not create any example where the benefits of parallelization was evident. Ex:

(->> data
       (map fn-transf1)
       (pmap fn-transf2)
       (filter fn-business1))


pmap is useful in a pretty narrow set of circumstances. The map task (fn-transf2) really needs to be pretty coarse grained to exceed the parallelization overhead


thanks @U064X3EF3 I thought so. I faced situations where I needed to perform ETL to several clients. We implemented the code to handle 1 client and used pmap to run for all of them later. However, even in this scenario, I'm feeling that I would like more control about the processes that are running. For example, the number of threads, backpressure and so on. Is this a valid concern? Is pmap being applied in the a proper scenario?


pmap is good for a quick hack. For anything serious, I usually don’t want the laziness that pmap includes and I just a Java executor to get more control or a lib like claypoole

👍 1

Hello! I would love a critique on this little temperature converter program if willing. My concerns/questions: 1) Almost all my functions have side effects, right? If a function calls another function that has side effects is that now considered also impure? How do I make this more pure? 2) How would you approach error handling? If the input isn't perfect this thing won't work. 3) How to approach looping this so you can keep inputting temps until you write "quit"? Every attempt I make hasn't worked right, I'm not sure if I'm understanding the underlying mechanics behind flush and read-line maybe. 4) I also need to handle negative temps so would like to see how you would take and parse user input that makes this all a bit better. Thank you!


@chase-lambert I made some changes to the code with some comments:, I hope it’s useful 🙂


This is perfect! Exactly what I was looking for. Thank you! Already, just using str instead of println to make the parsing pure is such a "d'oh! of course" moment

👍 1