简体   繁体   English

将DELETE请求用于REST中不完全删除

[英]Use DELETE request for not purely deletion in REST

I have a dilemma regarding the design of my REST API in Spring. 我在春季对REST API的设计感到困惑。

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. 有通过调用DELETE: /v1/api/users/{userId}来删除用户的DELETE请求DELETE: /v1/api/users/{userId} ,但这不是纯粹的用户删除,我必须在删除之前将用户票证重新分配给另一个活动用户。

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. 用户A有5张票证,当我删除用户A时,他/她的所有票证将重新分配给另一个选定的用户,然后将用户A从系统中删除。

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 并带有以下内容以接受ID进行重新分配

@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. 我的直觉告诉我,这不是设计DELETE请求API的好方法,删除应该只执行删除应该做的事情,我想了很长时间,但找不到一种优雅的方法。 Any ideas? 有任何想法吗?

Let's imagine you have cases associated to a user. 假设您有与用户关联的案例。

I would build a rest API like that: 我会像这样建立一个REST API:

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. 如果客户致电DELETE / v1 / api / user / {id},并且该用户有个案分配给他。 You can return an HTTP code 409 CONFLICT indicating you can't delete because of inherited objects. 您可以返回HTTP代码409 CONFLICT,指示由于继承的对象而无法删除。 The client will have to PUT /v1/api/user/{id}/case to associate these cases to somebody else. 客户端必须将PUT / v1 / api / user / {id} / case关联到其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM