Hi, I’d like to know your thoughts on how to represent deeply nested objects.
From what I understand, all related objects should be returned from the relationships
field. What is better when we have reasonably deep related object, relationships
or attributes
?
For example:
Representing it as a complex object:
{
"data": {
"type": "type-a",
"id": 1,
"attributes": {
"type_b_list": [{
"id": 2,
"type_c_list": [{
"id": 3,
"type_d_list": [],
"type_e_list": []
}]
}]
}
}
}
Representing proper relationships to follow the spec/sematics:
{
"data": {
"type": "type-a",
"id": 1,
"relationships": {
"type_b_list": {
"id": 2,
"type": "type-b"
}
}
},
"included": [
{
"id": 2,
"type": "type-b",
"relationships": {
"type_c_list": [
{
"id": 3,
"type": "type-c"
}
]
}
}
]
}
The the second example, how does include
work with deeply nested objects? What If I’d like to be able to return upto type-e
depth (or even more)?
I don’t think having multiple round trips to get each related resource in separate request is feasible.
Other alternative would be to follow the JSON:API resource object structure (type/id/attributes etc.) in the example 1 when representing nested objects.
What do you think?