简体   繁体   English

REST API的后端交易

[英]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中处理此问题时,我想执行以下操作-

  • 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应该没有意识到)

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);
}
  1. I am confused with the REST API approach as they only update the resource. 我对REST API方法感到困惑,因为它们仅更新资源。 Doesn't updating a resource change other underlying particulars in the application? 更新资源不会更改应用程序中的其他基础信息吗?
  2. Reading about REST confuses on how transactions atomicity is tackled. 阅读有关REST的文章混淆了如何解决事务原子性。 What is the solution for such activities in REST? REST中此类活动的解决方案是什么?
  3. I cannot do these multi-saves from the client (javascript) using multi-phase approach (saving transaction first, then with transaction id creating ledger etc) as the client application should be unaware of such back-end service-related actions. 我无法使用多阶段方法(先保存交易,然后使用交易ID创建分类帐等)从客户端(javascript)进行这些多次保存,因为客户端应用程序应该不了解此类与后端服务相关的操作。

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.

相关问题 使用Java Rest API作为后端的Angular JS登录 - Angular JS login with java rest api as backend REST API后端的Web应用程序身份验证 - Web App Authentication for REST API Backend 如何使用 Spring 引导验证 REST API 中的金融交易? - How to validate financial transactions in REST API with Spring Boot? 从我的 Spring Boot Rest API 返回的响应与提供给我的 rest API 的后端 API 不同 - Response returned from my Spring Boot Rest API is not same as the backend API provided to my rest API 前端应用程序和另一个后端服务使用的REST API的身份验证方法 - Authentication approach for REST API used by frontend app and another backend service 如何在Java中使用parse.com创建REST API后端? - How to create REST API backend using parse.com in Java? Odoo REST API是否允许登录到Odoo Web UI后端? - Does Odoo REST API allow login to Odoo Web UI backend? 为Spring Boot REST api后端构建Web前端? - Building a web frontend to a Spring boot REST api backend? 如何在springboot rest api后端应用程序中存储用户个人资料图片 - how to store user profile pictures in springboot rest api backend application 调用 Spring 启动 Rest ZDB9742381014CA8DE638 时出现“java.sql.SQLException:Transactions not supported”错误 - Getting “java.sql.SQLException:Transactions not supported” Error while calling Spring Boot Rest API with Informix Database
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM