简体   繁体   English

在部分失败的情况下进行REST API设计

[英]Rest API Design in case of partial failure

So I have a ticket booking system. 所以我有一个票务预订系统。

I have ticket booking request on API, from my application we call payment service. 我在API上有机票预订请求,在我的应用程序中我们称之为付款服务。

If failed on the first attempt we proceed by adding the message on the queue for handling payment later. 如果第一次尝试失败,我们将在队列中添加消息以供稍后处理。 And proceed with issuing the ticket to the customer. 并继续向客户发行票证。

From queue, we retry payment with payment API 10 times in 10 minutes if no success we add some status to that ticket booking record and by offline mean get money from the customer. 从队列开始,我们将在10分钟内重试10次使用付款API的付款,如果没有成功,我们会在该票务预订记录中添加一些状态,并且通过离线方式从客户那里取钱。

Problem : We are getting many such booking due frauds. 问题 :由于欺诈,我们收到了很多这样的预订。

Solution : 解决方案

I have a solution in mind, I will not proceed with issuing a ticket in payment fail, instead, I want to return something different HTTP code to the client. 我有一个解决方案,在付款失败时我不会继续发行票证,而是要向客户端返回一些不同的HTTP代码。 like everything else except payment is the success. 就像其他一切一样,除了付款就是成功。

And while processing the message from the queue if it fails after 10 attempts I want to inform client this transaction is failed. 在处理队列中的消息(如果尝试10次后失败)时,我想通知客户端此事务失败。

If pass let the client know to proceed with issuing the ticket 如果通过,请让客户知道继续发行票证

Question : Does this solution have technical feasibility? 问题 :此解决方案是否具有技术可行性?

I will not proceed with issuing a ticket in payment fail, instead, I want to return something different HTTP code to the client. 如果付款失败,我将不会继续发行票证,相反,我想向客户端返回其他HTTP代码。 like everything else except payment is the success. 就像其他一切一样,除了付款就是成功。

I would return 202 in case the payment is added to the queue. 如果付款已添加到队列中,我将返回202。

202 Accepted: The request has been accepted for processing, but the processing has not been completed. 202 Accepted:请求已被接受进行处理,但处理尚未完成。 The request might or might not eventually be acted upon, as it might be disallowed when processing actually takes place. 该请求最终可能会执行,也可能不会最终执行,因为在实际进行处理时可能会不允许该请求。 There is no facility for re-sending a status code from an asynchronous operation such as this. 没有从这种异步操作中重新发送状态代码的功能。

Otherwise, a 200 or 201 if it was successful. 否则,如果成功,则为200或201。

And while processing the message from the queue if it fails after 10 attempts I want to inform client this transaction is failed. 在处理队列中的消息(如果尝试10次后失败)时,我想通知客户端此事务失败。

A common notification mechanism is delivering a message via HTTP on some client specified endpoint. 常见的通知机制是通过HTTP在某些客户端指定的端点上传递消息。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM