Reputation: 4696
I have a dilemma regarding the design of my REST API in Spring.
Situation
There is DELETE request to delete users by calling DELETE: /v1/api/users/{userId}
, but it is not purely user deletion, i have to re-assign user tickets to another active user before deletion.
User A has 5 tickets, when i delete User A, all of his/her tickets will be re-assigned to another selected user, then user A is being deleted from the system.
My Initial Proposal
I use the most simple solution
DELETE: /v1/api/users/{userIds}
And also with the following to accept id for re-assignment
@RequestBody int assigneeId
My Dilemma
My gut tells me that this is not a good way to design a DELETE request API, delete should just do what delete should do, i thought it for long time but can't figure out an elegant way to do so. Any ideas?
Upvotes: 1
Views: 225
Reputation: 676
Let's imagine you have cases associated to a user.
I would build a rest API like that:
GET /v1/api/user : Return all users
GET /v1/api/user/{id} : Return a user
POST /v1/api/user : Add a user
PUT /v1/api/user/{id} : Update a user
DELETE /v1/api/user/{id} : Delete a user
GET /v1/api/user/{id}/case : Get user's cases
PUT /v1/api/user/{id}/case : Reassign user's cases to another user [{id}]
If a client makes a call to DELETE /v1/api/user/{id} and this user has cases assign to him. You can return an HTTP code 409 CONFLICT indicating you can't delete because of inherited objects. The client will have to PUT /v1/api/user/{id}/case to associate these cases to somebody else.
Upvotes: 2