基于REST的API:我应该在哪里code我的工作流程? [英] RESTful API: Where should I code my workflow?

查看:191
本文介绍了基于REST的API:我应该在哪里code我的工作流程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个RESTful API。这是我的第一个API,也是我第一次真正的大项目编码。因此,我仍然在学习了很多关于建筑等。

I am developing a RESTful API. This is my first API, but also my first really big coding project. As such, I'm still learning a lot about architecture etc.

目前,我有我的API建立在以下图层:

Currently, I have my api setup in the following layers:


  • HTTP层

  • 资源层

  • 域模型/业务逻辑层

  • 数据访问/库层

  • 永久存储/ DB层

我在此刻遇到的问题是我在哪里需要把工作流对象/经理人?通过工作流,我的意思是code,其值是什么最终用户所需的下一个步骤。例如,电子商务的工作流程。用户添加项目到购物篮,然后检查出来,然后填写个人详细信息,然后支付。工作流将负责决定的步骤是什么其次,还需要什么步骤,是不允许的。例如,用户可以不通过尝试支付他们已经输入的个人信息之前引起在API中的错误(也许他们回忆的URI付款和尝试跳过一工序)。工作流将检查所有previous步骤已经完成,如果没有,也不会允许付款。

The issue I have run into at the moment is where do I need to put workflow objects / managers? By workflows, I mean code that evaluates what next step is required by the end user. For example, an e-commerce workflow. User adds item to basket, then checks out, then fills in personal details, then pays. The workflow would be responsible for deciding what steps are next, but also what steps are NOT allowed. For example, a user couldn't cause errors in the API by trying to pay before they have entered personal details (maybe they recall the URI for payments and try to skip a step). The workflow would check to see that all previous steps had been completed, if not, would not allow payment.

目前,我的工作流逻辑是在资源层。我使用的超媒体链接至present的工作流程,用户如提供了一个下一步链接。我有这样的问题是,资源层是顶层层,用presentation更加对齐。我觉得它需要知道太多关于底层的域模型有效地评估工作流程,即它需要知道它有让付款前检查 personal_detail 鬼恋。

Currently, my workflow logic is in the Resource Layer. I am using hypermedia links to present the workflow to the user e.g. providing a 'next step' link. The problem I have with this is that the resource layer is a top level layer, and more aligned with presentation. I feel it needs to know too much about the underlying domain model to effectively evaluate a workflow i.e. it would need to know it has to check the personal_details entity before allowing payment.

这现在导致我以为工作流程中的域模型的归属。这确实让很多更有意义,因为真正的工作流程是业务逻辑的一部分,我思故最好放在领域层。毕竟,更换别的资源层,你仍然需要底层的工作流程。

This now leads me to thinking that workflows belong in the domain model. This does make a lot more sense, as really workflows are part of the business logic and I think are therefore best placed in the domain layer. After all, replace the Resource Layer with something else, and you would still need the underlying workflows.

但现在的问题是,工作流需要多个领域对象的知识来完成他们的逻辑。现在感觉不错,这也许去在自己的层?之间的资源和领域层?

But now the problem is that workflows required knowledge of several domain objects to complete their logic. It now feels right that it maybe goes in its own layer? Between Resource and Domain Layer?


  • HTTP层

  • 资源层

  • 工作流层

  • 域模型/业务逻辑层

  • 数据访问/库层

  • 永久存储/ DB层

我只是想知道如果任何人有解决这个其他任何意见或想法?正如我所说,我没有过去的应用经验知道在哪里工作流程应放置。林真的只是学习这是第一次所以要确保我将它以正确的方式。

Im just wondering if anyone had any other views or thoughts around this? As I said, I have no past application experience to know where workflows should be placed. Im really just learning this for the first time so want to make sure I'm going about it the right way.

链接到文章或博客覆盖,这将大大AP preciated。爱读书了不同的实现。

Links to articles or blogs that cover this would be greatly appreciated. Love reading up on different implementations.

修改

要澄清,我释放HATEOAS允许客户通过工作流程浏览,但必须有东西在我的API,它知道什么链接,显示即,它是真正定义所允许的工作流程。它美元的资源p $ psents工作流程相关的链接,但另外它验证请求在与工作流的同步。虽然我同意,客户可能只会遵循资源,其余的危险(美容)提供的链接,是其URI驱动的,所以有什么能够阻止一个淘气的客户试图跳过通过在工作流程步骤使得在URI的猜测。该API需要发现它并返回302响应。

To clarify, I release that HATEOAS allows the client to navigate through the 'workflow', but there must be something in my API that knows what links to show i.e. it is really defining the workflow that is allowed. It presents workflow related links in the resource, but additionally it validates requests are in sync with the workflow. Whilst I agree that a client will probably only follow the links provided in the resource, the danger (and beauty) of rest, is that its URI driven, so there is nothing stopping a mischievous client trying to 'skip' steps in the workflow by making an educated guess at the URI. The API needs to spot this and return a 302 response.

推荐答案

在回答这个问题花了我的研究公平一点,但基本上是工作流程的一部分无关与REST的一切,更多的事情要做与应用层

The answer to this question has taken me a fair bit of research, but basically the 'workflow' part has nothing to do with REST at all and more to do with the application layer.

我的系统是有太多紧耦合应用逻辑和REST API。我通过重构降低耦合解决我的问题,现在的生活工作流应用程序

My system was had the application logic and REST API too tightly coupled. I solved my problem by refactoring to reduce the coupling and now the workflow lives within the context of the application

这篇关于基于REST的API:我应该在哪里code我的工作流程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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