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

#links - representing an array of one link as just the link #61

Closed
andresf opened this issue Feb 5, 2013 · 6 comments
Closed

#links - representing an array of one link as just the link #61

andresf opened this issue Feb 5, 2013 · 6 comments

Comments

@andresf
Copy link
Contributor

andresf commented Feb 5, 2013

This is a nice to have, as the implementation is HAL compliant at the moment.

For an array of links, the number of links may vary based on the request or the state of the resource, and ideally if only one link is necessary it would be rendered as just the link and not an array of one link.

Explained in code:

links :thumbnail do
  links = []

  links << { href: small_thumbnail_url, name: "small" }
  links << { href: large_thumbnail_url, name: "large" } if large_thumbnail

  links
end

Which right now gets represented as either:

One link:

"thumbnail": [
  {
    "href": "thumbnail/small", "name": "small"
  }
]

Two links:

"thumbnail": [
  {
    "href": "thumbnail/small", "name": "small"
  },
  {
    "href": "thumbnail/large", "name": "large"
  }
]

Ideally the single link should just be represented as:

"thumbnail": {
  "href": "thumbnail/small", "name": "small"
}

In particular I'd like to see this because otherwise clients can create false expectations about how multi-link rels work, but it's very low priority to be honest.

@apotonick
Copy link
Member

Isn't it dangerous to change the representation format of your links depending on the amount? My idea was: By using either ::link or ::links I clearly state "this rel will have 1 link, this rel will have 1-n links and hence a different representation, namely an array". That being defined, the client can always rely on the link format and doesn't have to check whether it's an array or a single link!

@mikekelly
Copy link

Yes exactly as nick says, it is a better idea to pick an array or single object up front as you would with any normal Jason property.

@mikekelly
Copy link

Autocomplete fail.

@andresf
Copy link
Contributor Author

andresf commented Feb 6, 2013

Gotcha, I misunderstood the intent from other conversations.

Closing it!

@andresf andresf closed this as completed Feb 6, 2013
@apotonick
Copy link
Member

Who's Jason?

@mikekelly
Copy link

:)
On 6 Feb 2013 16:57, "Nick Sutterer" notifications@github.com wrote:

Who's Jason?


Reply to this email directly or view it on GitHubhttps://github.com//issues/61#issuecomment-13192290.

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

No branches or pull requests

3 participants