A self-reference relationship occurs when a resource points to another resource of the same type. The reference targets the resource type, not the resource itself. This pattern commonly represents trees, hierarchies, and directed graphs. section 4.1.1
Company directory
An Employee resource can reference other Employee resources as its manager or assistant. For example, one employee may report to another, while also identifying that person as an assistant or another special relationship. section 4.1.1
Following users
A User resource can reference many other User resources that it follows, while each user can have many followers. This many-to-many self-reference models a social network but can become expensive at large scale. section 4.2.1
Design self-reference relationships deliberately:
- Use them when the relationship is purposeful and fundamental to the API. section 4.2.1
- Estimate long-term operational cost before adding dense webs of references. section 4.2.1
- Account for cascading effects: deleting a highly connected user may require updating or removing millions of related records. section 4.2.1
Visualizes an Employee resource pointing to other Employee resources as manager and assistant. section 4.1.1
