clojure-australia

lsenjov 2020-11-17T01:07:50.067500Z

Good morning everyone

lsenjov 2020-11-17T01:08:19.068100Z

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

πŸŽ‰ 1
lsenjov 2020-11-17T01:08:22.068300Z

It’s a bit nutty

Hugh Powell 2020-11-17T22:00:42.069200Z

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

1
lsenjov 2020-11-17T23:03:33.070Z

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

Hugh Powell 2020-11-17T23:06:13.071500Z

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

πŸ‘ 1
lsenjov 2020-11-17T23:07:33.072100Z

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

πŸ‘ 1
anonimitoraf 2020-11-18T10:15:24.072300Z

Oh what do you mean?

lsenjov 2020-11-18T10:41:53.072500Z

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

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

lsenjov 2020-11-18T10:42:41.072700Z

So when you set things up, you do

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

lsenjov 2020-11-18T10:43:10.072900Z

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

lsenjov 2020-11-18T10:43:28.073100Z

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

lsenjov 2020-11-18T10:44:26.073300Z

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

lsenjov 2020-11-18T10:45:07.073500Z

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

anonimitoraf 2020-11-18T13:58:34.073700Z

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

πŸ‘ 1