如何以RESTful方式为CANCEL动作建模? [英] How to model a CANCEL action in a RESTful way?

查看:213
本文介绍了如何以RESTful方式为CANCEL动作建模?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在努力从整体中争夺较小的服务.我们的域名与票务系统非常相似.我们已决定从域的取消过程开始.

We are currently in the process of wrangling smaller services from our monoliths. Our domain is very similar to a ticketing system. We have decided to start with the cancellation process of the domain.

我们的取消服务具有简单的终结点"Cancel",其中包含票证的ID.在内部,我们检索id,执行一些与取消有关的操作,并更新商店中实体的状态.从商店的角度来看,已取消票和实时票之间的唯一区别是一些属性.

Our cancel service has as simple endpoint "Cancel" which takes in the id of the ticket. Internally, we retrieve the id, perform some operations related to cancel on it and update the state of the entity in the store. From the store's perspective the only difference between a cancelled ticket and a live ticket are a few properties.

根据我的阅读,PATCH似乎是在这种情况下使用的正确动词,因为它只是更新资源中的一个简单属性.

From what I have read, PATCH seems to be the correct verb to be used in this case, as am updating only a simple property in the resource.

PATCH /api/tickets/{id}
Payload {isCancelled: true}

但是isCancelled不是实体中的实际属性.在负载中发送不属于实体的属性是否公平,还是我应该考虑对请求进行建模的其他形式?我不想将整个实体作为有效载荷的一部分发送,因为它很大.

But isCancelled is not an actual property in the entity. Is it fair to send properties in the payload that are not part of the entity or should I think of some other form of modeling this request? I would not want to send the entire entity as part of the payload, since it is large.

我已经考虑过创建一个新资源CancelledTickets,但是在我们的域中,我们永远不需要对已取消的票证进行GET.因此,无需创建新资源.

I have considered creating a new resource CancelledTickets, but in our domain we would never have the need to a GET on cancelled tickets. Hence stayed away from having to create a new resource.

推荐答案

公开资源的GET接口不是强制性的.

Exposing the GET interface of a resource is not compulsory.

例如,使用

PUT /api/tickets/{id}/actions/cancel

提交取消请求.我选择PUT,因为实际上只有一个取消请求.

to submit the cancellation request. I choose PUT since there would be no more than one cancellation request in effect.

希望会有所帮助.

这篇关于如何以RESTful方式为CANCEL动作建模?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆