Skip to content

Instantly share code, notes, and snippets.

@landlessness
Last active February 8, 2016 22:18
Show Gist options
  • Save landlessness/068ee50b781b1737842b to your computer and use it in GitHub Desktop.
Save landlessness/068ee50b781b1737842b to your computer and use it in GitHub Desktop.
Flattened Entities Approach 1 : 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": ["tag"],
"rel": ["http: //rels.example.com/tag","hasMany"],
"properties": {"id": 1, "label": "foo"},
"links": [{"rel": ["self"], "href": "http://example.com/tags/1"}]
},
{
"class": ["tag"],
"rel": ["http: //rels.example.com/tag","hasMany"],
"properties": {"id": 2, "label": "bar"},
"links": [{"rel": ["self"], "href": "http://example.com/tags/2"}]
},
{
"class": ["tag"],
"rel": ["http: //rels.example.com/tag","hasMany"],
"properties": {"id": 3, "label": "baz"},
"links": [{"rel": ["self"], "href": "http://example.com/tags/3"}]
},
{
"class": ["comment"],
"rel": ["http: //rels.example.com/comment","hasMany"],
"properties": {"id": 1, "body": "ZOMG A COMMENT"},
"links": [{"rel": ["self"], "href": "http://example.com/comments/1"}]
},
{
"class": ["comment"],
"rel": ["http: //rels.example.com/comment","hasMany"],
"properties": {"id": 2, "body": "ZOMG ANOTHER COMMENT"},
"links": [{"rel": ["self"], "href": "http://example.com/comments/2"}]
}
]
}
{
"class": ["post"],
"properties": {
"id": 1,
"title": "New Post",
"body": "Body"
},
"links": [{"rel": ["self"],"href": "http: //example.com/posts/1"}],
"entities": [
{
"class": ["tag"],
"rel": ["http: //rels.example.com/tag","hasMany"],
"properties": {"id": 1, "label": "foo"},
"links": [{"rel": ["self"], "href": "http://example.com/tags/1"}]
},
{
"class": ["tag"],
"rel": ["http: //rels.example.com/tag","hasMany"],
"properties": {"id": 2, "label": "bar"},
"links": [{"rel": ["self"], "href": "http://example.com/tags/2"}]
},
{
"class": ["tag"],
"rel": ["http: //rels.example.com/tag","hasMany"],
"properties": {"id": 3, "label": "baz"},
"links": [{"rel": ["self"], "href": "http://example.com/tags/3"}]
},
{
"class": ["comment"],
"rel": ["http: //rels.example.com/comment","hasMany"],
"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","hasMany"],
"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