How do you represent "thin" and "fat" versions of a RESTful resource?

hateoas, hypermedia, rest

Solution

You could use the prefer header with the return-minimal parameter.

Problem

How would you model a resource that can have two different representations. For example, one representation may be "thin" withe most of its related resources accessible by links. Another representation may be "fat" where most of its related resources are embedded. The idea being, some clients don't mind having to make many calls to browse around the linked resources, but others want to get the data all at once. Consider a movie resource that is associated with a director, actors, etc. Perhaps the thin version of it has the movie title only, and to get the data for the director, list of actors, etc., one must make additional requests via the embedded links to them. Perhaps the fat version of it contains all the movie nested inside, including the director's data, the data for the various actor's, etc. How should one model this? I see a few options: - these two representations are really two different resources and require different URIs - these two representations are in fact the same resource, and you can select between the two representations via custom media types, for example `application/vnd.movie.thin+json` and `application/vnd.movie.fat+json`. - these two representations are in fact the same resource, and selecting the different representations should be done with query parameters (e.g. `/movies/1?view=thin`). - Something else... What do you consider the proper approach to this kind of API?

Original source

Related problems