How would you go about representing tree-structured data that contains links to other resources?
I want to expose a document’s hierarchical table of contents, which contains both section headings (not resources)* and sub-documents (resources).
Example:
Book 1 (heading)
> ... bla ... (sub-document)
> Chapter 1 (heading)
> > ... bla ... (sub-document)
Book 2 (heading)
> ... bla ... (sub-document)
> ... bla ... (sub-document)
My first thought was to have a “tableOfContents” attribute, but I think links are not allowed in attributes?
{
"data": {
"id": 1,
"type": "containerDocument",
"attributes": {
"tableOfContents": [
{
"type": "sectionHeading",
"attributes": { "title": "Book 1" },
"children": [
{
"type": "subDocument",
"id": "1234",
"links": {
"self": "/subDocuments/1234"
}
},
{
"type": "sectionHeading",
"attributes": { "title": "Chapter 1" },
"children": [
{
"type": "subDocument",
"id": "5678",
"links": {
"self": "/subDocuments/5678"
}
}
]
}
]
},
{
"type": "sectionHeading",
"attributes": { "title": "Book 2" },
"children": [
{
"type": "subDocument",
"id": "9012",
"links": {
"self": "/subDocuments/9012"
}
},
{
"type": "subDocument",
"links": {
"self": "/subDocuments/3456"
}
}
]
}
]
}
}
}
Can I model this as a relationship instead? If so, how?
The sub-documents are accessible via their own URL routes and it would be nice to have them include
-able in requests for the table of contents resource.
Any help is much appreciated!
*(My data source does have IDs for the headings, so they could theoretically be resources…)