For example, a team can have multiple players, and a player can belong to multiple teams, which forms a many-to-many relationship. In view of this situation, how should RESTful interface be designed?
POST: /teams/1/players/ PUT: /teams/1/players/1/
Which of the two is more suitable, I prefer the second one.
Besides update, because it is the relation of N:N, the relation table may have the following data
If I want to change player_id 1 and team_id 2 to team_id 3 …. if the interface is designed as
The player_id of 1 and team_id of 1 will also be changed to team_id of 3 …. obviously not what I want …
How to design?
New: POST /players
Update: PUT/PATCH /players/:id
Your main body is player, so just pass team_id in as a parameter.