简体   繁体   English

使用HTTP DELETE方法取消正在进行的操作

[英]Using HTTP DELETE method to cancel an action in progress

Background: 背景:

I provide a programming interface for people who wish to place orders using my site. 我为希望使用我的网站下订单的人提供编程界面。

They can use GET and POST methods on /api/v1/orders to place an order and to view list of all orders placed by them. 他们可以在/api/v1/orders上使用GETPOST方法/api/v1/orders订单并查看他们下的所有订单的清单。 They can also use the GET metod on /api/v1/orders/<order_id> in order to view specific details of one order. 他们还可以使用/api/v1/orders/<order_id>上的GET方法来查看一个订单的具体细节。

There is a need to provide a way to cancel an order, however the records themselves need to be kept. 需要提供取消订单的方法,但是需要保留记录本身。

I would like to get feedback from more seasoned developers on whether it would be a sane decision to: 我想得到更多经验丰富的开发人员的反馈意见,了解是否能做出明智的决定:

a) implement the DELETE verb on /api/v1/current_orders/<order_id> , which would delete it from the list of "current" orders (by marking it as cancelled). a)/api/v1/current_orders/<order_id>上实现DELETE动词,这将从“当前”命令列表中删除它(通过将其标记为已取消)。 The downside is that it will make use of a different noun, which may be confusing. 缺点是它将使用不同的名词,这可能会令人困惑。

b) implement the DELETE verb on /api/v1/orders/<order_id> with the same functionality as in a). b)/api/v1/orders/<order_id>上实现DELETE动词,其功能与a)相同。 This is somewhat misleading, as the entity will not really be deleted, and the consumer should be aware of that. 这有点误导,因为实体不会真正被删除,消费者应该意识到这一点。

c) implement the POST verb on /api/v1/cancellations/<order_id> (or POST on /api/v1/cancellations with the order_id in the JSON payload). c)/api/v1/cancellations/<order_id>上实现POST动词(或使用JSON有效载荷中的order_id对/api/v1/cancellations进行POST )。 This seems to be less than ideal because a resource will not be created as a result of that request. 这似乎不太理想,因为该请求不会创建资源。 However, the consequences of using this endpoint seem to be clearer. 但是,使用此端点的后果似乎更清晰。

d) ...? d) ......?

Question: 题:

I am aware that there is not always a "perfect" solution to designing endpoints for a REST API, but keeping in mind the need for clarity and intuitiveness and with a high regard for best practices , which of the options is "optimal" ? 我知道,为REST API设计端点并不总是一个“完美”的解决方案,但要记住需要清晰直观 ,并且要高度重视最佳实践哪些选项是“最优的”

What about PATCH verb on /api/v1/orders/<order_id> indicating that it is cancelled? /api/v1/orders/<order_id>上的PATCH动词如何表示它被取消了?

HTTP PATCH : Allows to do partial modifications in an entity. HTTP PATCH :允许在实体中进行部分修改。 While POST creates a new one, and PUT replaces an existing one, PATCH just updates the properties you are sending, leaves the rest at they are. 当POST创建一个新的,并且PUT替换现有的一个时,PATCH只更新你发送的属性,剩下的就是它们。

You would need only to send something like { isCancelled:true} as HTTP PATCH , then your code would update the entity and take action like cancel any outstanding work. 您只需要将{ isCancelled:true}作为HTTP PATCH ,然后您的代码将更新实体并采取行动,例如取消任何未完成的工作。

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

相关问题 请求的资源不支持http方法&#39;DELETE&#39; - The requested resource does not support http method 'DELETE' 使用HTTP DELETE审核内容 - Moderate content using HTTP DELETE 如何在不实际执行HTTP DELETE操作的情况下对其进行建模 - How to model the consequences of HTTP DELETE action without actually doing it 使用.filter方法删除Function - Delete Function using .filter Method 带有进度条和“取消”按钮的 Revit 外部命令 - Revit external command with progress bar and 'Cancel' button 如何使用条带代码(检索和删除)使用 Nodejs 从 Stripe 检索和取消订阅? - How to use the stripe code (Retrieve and Delete) to retrieve and cancel a subscription from Stripe using Nodejs? 如何在 Laravel 中使用 HTTP 请求的删除方法通过外部 Api 库删除项目 - How to use HTTP request's delete method in Laravel to delete item via external Api library 在RESTful应用程序中,我们如何区分“动作”和HTTP动词(GET,POST,PUT,DELETE)? - In a RESTful application, how do we differentiate between an “action” and an HTTP verb (GET, POST, PUT, DELETE)? 如何以 RESTful 方式对 CANCEL 操作建模? - How to model a CANCEL action in a RESTful way? 取消/杀死http api调用角度2 - Cancel /Kill http api call angular 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM