Should resources always include their relatives?


Staying with the common example of users (authors) and articles, when I request a user, should the returned resource include references to articles written by that user?

It could be argued that, because the article references the user (as being the author), the user is related to the article, but not vice-versa. The relation is the author, not the user and the author is maintained through the article.

I’m trying to decide whether both resources should present all relationships or only those which they maintain directly through an FK. But where would that leave me in regrades to n-m relationships?


The rule of thumb answer would be to include the things by default which make sense, are helpful to your consumers, and don’t bloat your responses beyond your idea of a reasonable limit. To answer your question specifically requires visibility into consumer needs, domain model knowledge, caching strategy, deployment strategy, etc…

A relationship is by definition bidirectional. However, it doesn’t mean it is always explicitly defined, or stored in a way which is easily referenced. Speaking in terms of traversing a graph, two points connected by a directed segment don’t somehow become unrelated in the context of the target point because of the absence of a traversal path to the source point.


Thank you. That’s is very helpful advise.