Skip to content
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

Support arrays of links with JSON HAL #33

Closed
acrispino opened this issue Jul 30, 2012 · 7 comments
Closed

Support arrays of links with JSON HAL #33

acrispino opened this issue Jul 30, 2012 · 7 comments

Comments

@acrispino
Copy link

JSON HAL spec (http://tools.ietf.org/html/draft-kelly-json-hal-03#section-4.1.1) says,

[_links] is an object whose property names are link relation types (as defined by [RFC5988]) and values are either a Link Object or an array of Link Objects.

Mike Kelly gives an example of what that looks like (https://groups.google.com/group/hal-discuss/msg/5afa41ab1740aee1):

{ 
 "_links": { 
   "self": { "href": "/product/987" }, 
   "upsell": [ 
     { "href": "/product/452", "name": "FP01", "title": "Flower pot" }, 
     { "href": "/product/832", "name": "HD77", "title": "Hover donkey" } 
   ] 
}

Presently, if you try to use an array of links, the output is more like:

{ 
  "_links": { 
    "self": { "href": "/product/987" }, 
    "upsell": {
      "href": [ "/product/452", "/product/832" ]
    }
  }
}
@apotonick
Copy link
Member

Oh I was hoping this is a pull request ;-)

@apotonick
Copy link
Member

So, to have links we currently have the following mechanics.

link :self do
  product_url(self)
end

link :rel => :self, :title => "Myself" do
  product_url(self)
end

I'd love to have the following.

link :self do
  {:title => full_title, :href => ..}
end

Here, you can return a hash where the block itself is executed in instance context, meaning you can access attributes of the represented object at runtime (like #full_title).

link :self, :array => true do
  [ {:title => full_title, :href => ..},
    ..
  ]
end

When :array => true is set, the link will be an array of LinkObjects following the HAL specification.

@dnd
Copy link

dnd commented Oct 25, 2012

Has the format

link :self do
  {:title => full_title, :href => ..}
end

been implemented yet? It sort of works, but I get the links nested under an href key:

"self":{
  "href":{
    "title":"Awesome generated name",
    "href":"/reports/20121025161822"
  }
}

I need to be able to access a method on the model to determine the proper title to display, and I can't do that by passing a hash to the link method itself.

@apotonick
Copy link
Member

Since this years' conference season is over for me I finally have time to code! Expect all of the upper behaviour in less than a week :-)

@locks
Copy link

locks commented Nov 5, 2012

sorry to ping you again about this, but it's a sticking point in my API

@locks
Copy link

locks commented Jan 6, 2013

🌟 🌟 💃 👯 💃 🌟 🌟

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants