Fork me on GitHub

Anyone using the Lapce editor for Clojure?


Anyone knows how to add a ring middleware to http-kit ? I need especially the wrap-params middleware


nevermind solved it allready 😄


(def my-server (hk-server/run-server (wrap-params #(ruuter/route (routes) %)) {:port 8080}))

💯 1

so just to wrap my head around it. the wrap-params function gets a function and returns the function with extra stuff around correct? So that it gives the underlying functions extra params in the request? Correct


100 % correct, as far as I can tell! > Middleware are higher-level functions that add additional functionality to handlers. The first argument of a middleware function should be a handler, and its return value should be a new handler function that will call the original handler.


i did a lot fp in js in the past but in lisp no clue why it feels harder for me to understand and grok 😄 i guess i just have to get even further around this parens. Even though i don't have struggle to read code and stuff no clue what is missing currently 😄


Personally, I’m not super comfortable writing middleware either 😅 I find that it can be hard to get the order of the middleware right, and when something goes wrong, the stack trace is just one big anonymous function. In my own code, I’ve sometimes introduced my own request-enter and response-exit functions. In your code, it could look something like this:

(defn request-enter [...])
(defn response-exit [...])
(defn app [req] (ruuter/route (routes) req))
(defn wrapped-app [req] (-> req request-enter app response-exit))
ring.middleware.params has a function ring.middleware.params/params-request you can be used in request-enter.


I’ve had plenty of times where there’s an advanced Clojure solution that I simply avoid. I accept writing more code, so that the code is more explicit, and I can understand what’s going on.

💯 1

i always try to make it easy to read cause i'm stupid 😄 and i know 2 weeks from now i would have no clue what i did 😄 so readability first imho.

❤️ 1