Suppose I have two entities
post, were every post has an author.
Implemented are these REST calls
Get a paginated list of posts:
Get a list of authors:
Get a single author:
Suppose I also have a client using the REST service. This client wants to show a paginated list of posts with related authors.
Now how would the REST service work regarding the related entities? There are the following methods:
GET /posts?page=1call return the posts and the related authors in a single call. Optionally make this a separate parameter, f.e.
Let the client loop through the posts and get the author for every post using the
Let the REST call for the authors accept a list of ID's as a filter, so the client can get the related authors in one call, f.e.
Method 1 is the easiest one from the client's perspective since it gets all the necessary data in one call. But the REST service is limited here, it shouldn't need to fit any particular client because every client has other requirements.
Method 2 is the cleanest REST approach, but let's say that a page has 30 posts, the client has to make 30 additional REST calls to retrieve the related authors. This is very inefficient.
Method 3 is perhaps better of the three, since it is a relatively clean REST implementation (compared to method 1) and it requires only one extra call per page.
Is there a recommended approach here?