You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
More concise use of parameterized liberator resources? #95
But (foo x) produces a handler function that closes over x, it seems since once again something was trying to cast a function to an associative structure.
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 :id route parameter to the resource but obviously that's not very useful alone, presume it wanted to look up the identifier somehow to produce a response:
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 (def routes ["/foo/" {[:id] (foo nil)}]), and then
(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.
Activity
malcolmsparks commentedon Nov 16, 2015
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.
jonathanj commentedon Nov 16, 2015
After filing this issue I experimented with some different approaches. My previous example just passed the
:idroute parameter to the resource but obviously that's not very useful alone, presume it wanted to look up the identifier somehow to produce a response: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.
zendevil commentedon Feb 23, 2020
@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
(def routes ["/foo/" {[:id] (foo nil)}]), and thenjonathanj commentedon Feb 23, 2020
(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.