-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More concise use of parameterized liberator resources? #95
Comments
Thanks for this. I don't think you are missing anything. Compojure uses a macro designed for destructuring route params, so is much better optimized for this example. I've toyed with some destructuring macro layered upon bidi but haven't come up with anything worthwhile yet. |
After filing this issue I experimented with some different approaches. My previous example just passed the (defresource foo [lookup-identifier]
:exists?
(fn [ctx] {::id (get-in ctx [:request :route-params :id])}
:handle-ok
(fn [ctx] (lookup-identifier (::id ctx))))
(def routes ["/foo/" {[:id] (foo db/lookup-identifier)}]) I'm quite happy with this since it reduces the complexity in my routes dramatically and factors my resources into a form that is better abstracted and so easier to test. Indeed, it would be nice to have the route parameters decoupled from the resource even further but even then I think writing some domain-specific convenience functions might give good results for my purposes. Thanks for taking a look though, I definitely wouldn't object to some convenience improvements to this aspect. |
@jonathanj, would you explain why this way "factors my resources into a form that is better abstracted and so easier to test"? i.e., why is it better than doing
|
(Disclaimer: This was posted 5 years ago, and I’m not sure I recall the specifics in great detail.) If I had to guess at answering your question, it’s because the “how to look up an identifier” is parameterised, instead of being baked into the resource as in your example. Which is easier to test and more reusable because the behaviour is supplied externally and can be varied as required by different callers, for differing data queries. |
I have some code:
This doesn't work as-is because something is trying to cast the
foo
function to an associative structure, so this seemed like it might work:But
(foo x)
produces a handler function that closes overx
, it seems since once again something was trying to cast a function to an associative structure.What I ended up with was:
Which is kind of messy, especially when compared to something like Compojure:
Am I missing something?
The text was updated successfully, but these errors were encountered: