Suppose I have two objects - a project team and an employee. Each employee can be part of several teams, and each team can have several employees as members of the team. I need to provide a REST API to manage teams, employees, and the relationships between them.
I defined 3 resources - the team, employee and member (the association between the team and the employee), which is a sub-resource of the team. The reason I chose a member as a sub-resource is based solely on the life cycle of that resource. Whenever a team is deleted, members are deleted, and also have no meaning outside the command itself.
I expose the following API (relevant):
POST /teams creates a new command entry with name, department identifier, etc.POST /teams/{name}/members creates a relationship between a team identified by name and a specific employee, so the input contains an employee identifier
I also need to provide an API to update the department ID and other team attributes on a single request. It seems that PUT is a natural choice, but the semantics of PUT are pretty clear - I need to replace the entire resource, which in this case means replacing all the sub-resources of the participants.
Which method (or approach) should I use when I want to update team attributes while maintaining member associations? Please keep in mind that I also want this request to be idempotent.
source
share