ja_serializer
ja_serializer copied to clipboard
Links at top level of resource collection
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"
}
}]
}
It looks like we either never had support for this or lost it at some point. I will get this in the next release.
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"