Skip to content

Instantly share code, notes, and snippets.

@landlessness
Last active February 8, 2016 22:18
Show Gist options
  • Save landlessness/9d4f035339469510de9d to your computer and use it in GitHub Desktop.
Save landlessness/9d4f035339469510de9d to your computer and use it in GitHub Desktop.
Nested Sub-Entities Under a Collection Approach 2 : Siren for Ruby's ActiveModelSerializer
{
"class": ["post"],
"properties": {
"id": 1,
"title": "New Post",
"body": "Body"
},
"links": [{"rel": ["self"],"href": "http: //example.com/posts/1"}],
"entities": [
{
"class": ["tags","collection"],
"rel": ["http: //rels.example.com/tags","hasMany"],
"links": [{"rel": ["self"], "href": "http://example.com/posts/1/tags"}],
"properties": {"count": 3}
},
{
"class": ["comments","collection"],
"rel": ["http: //rels.example.com/comments","hasMany"],
"links": [{"rel": ["self"], "href": "http://example.com/posts/1/comments"}],
"properties": {"count": 2}
}
]
}
{
"class": ["post"],
"properties": {
"id": 1,
"title": "New Post",
"body": "Body"
},
"links": [{"rel": ["self"],"href": "http: //example.com/posts/1"}],
"entities": [
{
"class": ["tags","collection"],
"rel": ["http: //rels.example.com/tags","hasMany"],
"links": [{"rel": ["self"], "href": "http://example.com/posts/1/tags"}],
"properties": {"count": 3}
},
{
"class": ["comments","collection"],
"rel": ["http: //rels.example.com/comments","hasMany"],
"links": [{"rel": ["self"], "href": "http://example.com/posts/1/comments"}],
"properties": {"count": 2},
"entities": [
{
"class": ["comment"],
"rel": ["http: //rels.example.com/comment"],
"properties": {"id": 1, "body": "ZOMG A COMMENT"},
"links": [{"rel": ["self"],"href": "http: //example.com/comments/1"}],
"actions": [
{"name": "delete", "method": "DELETE", "href": "http://example.com/comments/1"},
{"name": "update", "method": "PATCH", "href": "http://example.com/comments/1", "fields": [ {"name": "body" }]}]
},
{
"class": ["comment"],
"rel": ["http: //rels.example.com/comment"],
"properties": {"id": 2, "body": "ZOMG ANOTHER COMMENT"},
"links": [{"rel": ["self"],"href": "http: //example.com/comments/2"}],
"actions": [
{"name": "delete", "method": "DELETE", "href": "http://example.com/comments/2"},
{"name": "update", "method": "PATCH", "href": "http://example.com/comments/2", "fields": [ {"name": "body" }]}]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment