ja_serializer icon indicating copy to clipboard operation
ja_serializer copied to clipboard

Links at top level of resource collection

Open lleger opened this issue 9 years ago • 2 comments

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"
    }
  }]
}

lleger avatar Feb 07 '17 23:02 lleger

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

alanpeabody avatar Feb 08 '17 13:02 alanpeabody

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"

beerlington avatar Nov 10 '17 04:11 beerlington