Restful many-to-many relationships creation and update issues

  node.js, question

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?

First, create

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

id team_id player_id
1 1 1
2 1 2
3 2 1

If I want to change player_id 1 and team_id 2 to team_id 3 …. if the interface is designed as

PUT: /teams/3/players/1/

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.