Consider a user (/ users / {id}) who has a name and multiple locations (/ users / {id} / location).
When I ask the user (/ user / {id}), should this user be fully represented - his identifier, name and locations - or should the locations be returned only by a separate request? For example, what JSON DTO do you expect from a request for a user with id = 123 (/ users / 123):
1) {"id": 123, "name": "Peter", "locations": [{"id": 1, "name": "Chicago"}, {"id": 2, "name": " New York" }]}
2) {"id": 123, "name": "Peter", "locations": [{"id": 1}, {"id": 2}]}
3) {"id": 123, "name": "Peter", "locations": [1, 2]}
4) {"id": 123, "name": "Peter"}
Is it more subjective, pushing and pulling between the size of the DTO and the queries required in a typical use case? I tend to just include all the relevant data (1), but I'm not sure if this is better than just requiring developers to make a few calls to the API to get all the data they need.
source share