REST 中的事务? [英] Transactions in REST?

查看:36
本文介绍了REST 中的事务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道您如何在 REST 中实现以下用例.甚至有可能在不影响概念模型的情况下做到吗?

I'm wondering how you'd implement the following use-case in REST. Is it even possible to do without compromising the conceptual model?

在单个事务范围内读取或更新多个资源.例如,将 100 美元从 Bob 的银行账户转入 John 的账户.

Read or update multiple resources within the scope of a single transaction. For example, transfer $100 from Bob's bank account into John's account.

据我所知,实现这一点的唯一方法是作弊.您可以 POST 到与 John 或 Bob 关联的资源,并使用单个事务执行整个操作.就我而言,这破坏了 REST 架构,因为您实际上是通过 POST 对 RPC 调用进行隧道传输,而不是真正对单个资源进行操作.

As far as I can tell, the only way to implement this is by cheating. You could POST to the resource associated with either John or Bob and carry out the entire operation using a single transaction. As far as I'm concerned this breaks the REST architecture because you're essentially tunneling an RPC call through POST instead of really operating on individual resources.

推荐答案

考虑 RESTful 购物篮方案.购物篮在概念上是您的交易包装器.与您可以将多个项目添加到购物篮然后提交该购物篮以处理订单的方式相同,您可以将 Bob 的帐户条目添加到交易包装器,然后将 Bill 的帐户条目添加到包装器.当所有部分都到位后,您可以使用所有组件部分 POST/PUT 事务包装器.

Consider a RESTful shopping basket scenario. The shopping basket is conceptually your transaction wrapper. In the same way that you can add multiple items to a shopping basket and then submit that basket to process the order, you can add Bob's account entry to the transaction wrapper and then Bill's account entry to the wrapper. When all the pieces are in place then you can POST/PUT the transaction wrapper with all the component pieces.

这篇关于REST 中的事务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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