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 at top level of resource collection #222

Open
lleger opened this issue Feb 7, 2017 · 2 comments
Open

Links at top level of resource collection #222

lleger opened this issue Feb 7, 2017 · 2 comments

Comments

@lleger
Copy link

lleger commented Feb 7, 2017

I see there's an easy way to add links to an object via the location DSL or the links callback, but this only adds links to individual resources. Is there a way to add links to the top-level of a collection? For example, how can I do this:

{
  "links": {
    "self": "http://example.com/articles"
  },
  "data": [{
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "JSON API paints my bikeshed!"
    }
  }, {
    "type": "articles",
    "id": "2",
    "attributes": {
      "title": "Rails is Omakase"
    }
  }]
}
@alanpeabody
Copy link
Contributor

It looks like we either never had support for this or lost it at some point. I will get this in the next release.

@beerlington
Copy link
Contributor

I'm pretty sure this never existed but here are a couple ideas:

For non-DSL version it'd probably be easy to do something like this:

def links(data, conn) when is_list(data) do
  # ...
end
def links(data, conn) do
  # ...
end

For DSL version we could either offer a second function:

location "/articles/:id"
collection_location "/articles"

or add a function that takes both:

locations collection: "/articles", resource: "/articles/:id"

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

No branches or pull requests

3 participants