-1

Consider the following database scheme :

  • User (id, username, firstname, lastname, .....)
  • Group (id, name) // 3 entries administrator, approver or issuer
  • Project(id, name, launchdate, ....)

with a ternary association relating the three previous entities:

  • Membership(user_id, group_id, project_id)

I need to create a route to change the group for a specific user in a specific project.

What is the best RESTful Architecture to design this route?

First draft : PUT : api/membership/user_id/project_id/group_id

This route associate group with group_id to user if it doesn't exist and remove it if it's associated
Mark Chackerian
  • 21,866
  • 6
  • 108
  • 99
Clean coder
  • 147
  • 1
  • 9

1 Answers1

0

What is the best RestfullArchitecture to design this route.

Likely by exposing a membership resource

POST: /api/membership/
{
    'user': ...,
    'group': ...,
    'project': ...,
}

and

DELETE: /api/membership/{pk}

Alternatively, you could also create a "real" Group that would be linked to a projet and with the name among "administrator", "approver" or "issuer" and add users to them.

Linovia
  • 19,812
  • 4
  • 47
  • 48
  • for an SPA this makes a lot of front overhead like managin memberships primary keys – Clean coder Mar 14 '17 at 12:45
  • Which is why I added an alternative option which makes more sense in the long term. – Linovia Mar 14 '17 at 13:06
  • Conslusion: violating restfull constraints can make life much easier when dealing with SPA's – Clean coder Mar 14 '17 at 13:14
  • Bypassing constraints always makes life easier until the point you realize that easy is different from simple and start bringing back the constraints :) – Linovia Mar 14 '17 at 13:18
  • about maintainability I have a good idea about system evolution and this route will never be used in another context. – Clean coder Mar 14 '17 at 13:43