-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Generate Hal? #387
Generate Hal? #387
Conversation
I would be happy including something like that in the default, or making it |
I'll turn this into a pull request, then. I hit one thing so far that may require some changes to existing AM::S code (or at least be way easier that way), so that seems preferable to me. More details to come, after some commits. Thanks. |
_links.each do |rel, options| | ||
method << " h[:\"#{rel}\"] = {\n" | ||
method << " href: \"#{options[:href]}\",\n" | ||
method << " templated: #{!!options[:templated]}\n" if options[:templated] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was writing this into the actual project I'm working on, I had the links api working like this:
link :posts, route: :posts, template: '{?published_before,published_after}'
link :self, route: :post, params: [object.id]
And then the above code would use the :route
option to build a url helper, passing :params
and/or appending the :template
as appropriate.
But this gem doesn't actually have a runtime dependency on Rails, so it seemed inappropriate to build that in, so now it takes :href
and :templated
(just like HAL links) and just passes them along.
Anyone have opinions on this aspect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I think passing in the href here is the way to go. To that end, I wrote Zooplankton to aid in turning Rails routes into URI Template strings.
I added code that will properly set up I am pretty happy with how easy this was to implement. |
I've expanded how the
The bit about self links that I left in my README edits paired with my |
Hey Ben, I'm not interested in pulling this into master at this time. But, if you check out https://groups.google.com/forum/#!topic/rails-api-core/8zu1xjIOTAM, please note that I would like HAL to be in the 0.10 series, and we'd love a hand with that. Maybe some stuff from this PR can be used there. |
I started playing around with subclassing
ArraySerializer
andSerializer
that would help generate HAL JSON more easily. They're still pretty naive, but I've made enough progress that I feel pretty confident they could be done well. Is this something y'all'd be interested in putting in this gem, or should I think about making a separate one, probably with a dependency on this one?