[英]Backend transactions with REST API
I have a question on REST API and how to create some back-end transactions in our application. 我对REST API以及如何在我们的应用程序中创建一些后端事务有疑问。 We have an accounting application, and so for every transaction created there is a ledger entry.
我们有一个会计应用程序,因此对于创建的每个交易都有一个分类帐条目。 (though client - javascript is unaware of such entries)
(尽管客户端-javascript无法识别此类条目)
For instance, in REST we create a transaction through - 例如,在REST中,我们通过-创建交易
POST /transactions/
(or) (要么)
POST /accounts/1223/transactions/
Now, when I deal with this in RestController, I want to do the following - 现在,当我在RestController中处理此问题时,我想执行以下操作-
In the TransactionService in spring java app (this should be immaterial though, as my question is focused on REST API semantics), 在Spring Java应用程序的TransactionService中(尽管这应该无关紧要,因为我的问题集中在REST API语义上),
@Transactional
public void saveTransaction(Transaction t) {
transactionRepo.save(t);
Ledger l = new Ledger(<particulars>)();
ledgerRepo.save(l);
Balance b = balanceService.get(<partiulars>);
balanceRepo.update(b);
}
Could someone explain clearly in this particular scenario how to approach? 有人可以在这种特定情况下清楚地说明如何处理吗?
Many applications are finance and accounting related, but I just don't get why REST won't fit for such practical scenario. 许多应用程序与财务和会计相关,但是我不明白为什么REST无法适合这种实际情况。 Might be my understanding is different.
可能是我的理解不同。
when I deal with this in RestController, I want to do the following -
当我在RestController中处理此问题时,我想执行以下操作-
- Create the Transaction based on POST.
基于POST创建事务。
- Create a ledger entry in the back-end.
在后端创建一个分类帐条目。 (Client - javascript should be unaware)
(客户端-javascript应该没有意识到)
- Update the balance entry on the account.
更新帐户上的余额条目。 (Client - javascript should be unaware)
(客户端-javascript应该没有意识到)
That all seems pretty reasonable. 一切似乎都很合理。
I am confused with the REST API approach as they only update the resource.
我对REST API方法感到困惑,因为它们仅更新资源。
So my diagnosis is that you are a victim of semantic diffusion ; 所以我的诊断是你是语义传播的受害者; how much did the meaning of REST change before you learned it?
REST的含义在您了解之前发生了多少变化?
Your best starting point may be Jim Webber's 2011 talk 您最好的起点可能是吉姆·韦伯(Jim Webber)在2011年的演讲
You have to learn how to use HTTP to trigger business activity as a side effect of moving documents around the network.
您必须学习如何使用HTTP触发业务活动,这是在网络上移动文档的副作用。
HTTP tells you what the semantics of the requests are -- that's what REST calls the "uniform interface" -- but it doesn't say anything about the side effects. HTTP告诉您请求的语义是什么-REST称之为“统一接口”-但是它没有说明任何副作用。 The fact that, in your domain, you respond to a POST request by updating ledgers and balances is fine .
在您的域中,您可以通过更新分类帐和余额来响应POST请求,这一事实很好 。
If it helps: it's exactly the same way a web site works. 如果有帮助,则与网站的工作方式完全相同。 You fill in a form and submit it, and some web page (resource) changes as a result, but also a bunch of interesting things happen on the back end.
您填写表格并提交,结果导致某些网页(资源)发生变化, 但后端也会发生很多有趣的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.