clojure-australia 2020-11-17

Morning πŸ‘‹ It's that time, I'm actually going to understand how Ring works today.

πŸ€” 1

Morning! Raw ring, or adding compojure/reitit on top of it @hugh336?

I'm trying to teach myself reitit and realising an understanding of Ring would be helpful πŸ™‚

πŸ‘ 1

You should be good, only weirdness to remember is middleware wraps from the inside out

πŸ‘ 1

Oh what do you mean?

So ring middleware is fairly simple, it follows the format:

(defn wrap-something [handler]
  (fn [request]
    (-> request
        do-before
        handler
        do-after)))

So when you set things up, you do

(-> handler
    wrap-first
    wrap-second
    wrap-third)

So when this endpoint is called, it calls the do-before of wrap-third first, then wrap-second and wrap-first

Then when returning, it does the do-after of wrap-first, then wrap-second, then wrap-third

It’s not particularly difficult, it just took my head a little to get around when I had to write middleware

Once you understand the pattern, it’s pretty simple to write your own middleware

Right, I think I get the gist of it. I havent used ring before but I know the concept of middlewares with expressjs

πŸ‘ 1

Good morning everyone

I got GET requests working at 2am last night, macro’d out from a small model

πŸŽ‰ 1

It’s a bit nutty