I'm working to design a
REST API to be consumed by a
The client-side of the SPA queries data about a relationship between two entities:
Teams have many
Players can only belong to one
I want to query all the
Teams and then get all the
Players for each team (which you could imagine would be a fairly typical use-case for these resources in a SPA.)
I can see 3 main approaches:
/teamsendpoint to have some param
?expand=playeror something similar that includes a player array for each team. The data comes back nice to be consumed by the react application but now the REST API endpoint is becoming more complex and less compliant to the single-responsibility principle.
/teamsto get the IDs of all teams and then query each team
/team/:id/players. But this will increase the # of requests to the backend, although it will separate responsibilities nicer and make things more explicit.
/teamsto get the IDs of all teams and then query
:idsis the IDs of all the teams. This is also quite explicit but could result in a huge URL and isn't a nice and tidy.
What approach is generally regarded as the best? Of course all of them have trade-offs, but perhaps I am overlooking some trade-offs?