4 ms·
I have a couple of suggestions. 1. If you return a handler function from a Compojure route, the handler is evaluated with the request. So: (GET "/" reques
by weavejester 14y ago
I have a couple of suggestions.
1. If you return a handler function from a Compojure route, the handler is evaluated with the request. So:
(GET "/" request (posts/all request))
Is the same as:
(GET "/" [] posts/all)
So there's no need for a separate "route" macro.
However, passing the full request map is discouraged, because the more information you give a function, the more things can theoretically affect it. Functions should be limited in what they know and what they can do, and this is one of the principles Compojure is designed around.
2. Some of the macros you've written for Korma could be written as functions instead. For example:
(defn paginate [query page per-page]
(-> query (limit per-page) (offset (dec page))))
(post/all (where conditions) (paginate page per-page))
- nonrecursive 14y agoThank you! And thank you for making such great libraries available. For #1, I definitely started by not passing the full request map but I ended up finding it cumbersome. On the other hand, my code doesn't really need the full request map. I'll have another go at it and see how I can improve things - thanks for the guidance. It feels like a process of over-contraction, then over-expansion. Hopefully I'll find a happy medium. For #2 - thank you! I was trying to work toward something like but couldn't quite get there, so this is great.
- weavejester 14y agoCould you give me an example of a route that was particularly messy if you didn't pass the full request map? Maybe I can suggest a better option (or at least admit defeat :)
- nonrecursive 14y agoYou know, I actually can't think of any. I just ended up writing things the way I did because I anticipated I would want the full request map, but that assumption hasn't born out. Passing params might be a good way to go. I need to go back and change this!
- deleted 14y ago[deleted]
- deleted 14y ago[deleted]