Fork me on GitHub
#clojure-australia
<
2020-11-17
>
lsenjov01:11:50

Good morning everyone

lsenjov01:11:19

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

🎉 3
lsenjov01:11:22

It’s a bit nutty

Hugh Powell22:11:42

Morning 👋 It's that time, I'm actually going to understand how Ring works today.

3
lsenjov23:11:33

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

Hugh Powell23:11:13

I'm trying to teach myself reitit and realising an understanding of Ring would be helpful 🙂

👍 3
lsenjov23:11:33

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

👍 3
anonimitoraf10:11:24

Oh what do you mean?

lsenjov10:11:53

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

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

lsenjov10:11:41

So when you set things up, you do

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

lsenjov10:11:10

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

lsenjov10:11:28

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

lsenjov10:11:26

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

lsenjov10:11:07

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

anonimitoraf13:11:34

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

👍 3