A parent–child relationship models true ownership or containment between resources. The child belongs to one parent, and actions or properties can cascade from parent to child, such as deletion or access control. section 4.1.1 section 4.2.3
Use hierarchy when the relationship has these characteristics:
- Deleting the parent should normally delete its children. section 4.2.3
- Access to the parent should imply the same level of access to the child. section 4.2.3
- The child has one parent rather than many; use a reference relationship when resources are merely associated or can change parents. section 4.2.3 section 6.3.6
Chat rooms and messages
Model Message resources beneath ChatRoom resources when deleting a chat room should delete its messages and granting access to the room should grant access to those messages. Conversely, do not encode a mutable association as ownership: if a book can move between shelves, store shelfId on Book rather than using an identifier such as shelves/1/books/1. section 4.2.3 section 6.3.6
Figure 4.5 ChatRoom resources act as the owner of Message resources through hierarchical relationships.
Inspect the resource layout showing ChatRoom resources owning Message resources. section 4.1.1

