Search code examples
apiasp.net-coreapi-design

API paths for Many to Many relationship


I have the following entities on an Api:

Organization > OrganizationId (PK), Name, ...

User > UserId (PK), Name, ...

OrganizationEnrolment > (OrganizationId, UserId) (PK), EnromentTypeId

So OrganizationEnrolment has the enrolments of users in organisations.

An user can only have one enrolment per Organization so the PK (OrganizationId, UserId).

I have a few API endpoints like:

GET Organization = GET organizations/{organizationId}

Update Organization = PUT organizations/{organizationId}

Create User = POST users

Delete User = DELETE users/{userId}

The question is:

What should be the API urls to Create, Delete and Update an Organization Enrolment?

I am struggling with it ...


Solution

  • Get Organization Employees: GET organizations/{organizationId}/employees

    Attach Employees to Organization: PUT organizations/{organizationId}/employees

    Remove Employees from Organization without deleting Employees: DELETE organizations/{organizationId}/employees