On which layer do you put your REST api?

Our application is structured like this:

UI ↔ REST API ↔ Workflow ↔ Business Logic ↔ DAL ↔ DB

However, I see a few examples where it seems like people are doing

UI ↔ Workflow ↔ REST API ↔ Business Logic ↔ DAL ↔ DB

Is that my imagination? Or is the second option considered a viable alternative?

+4
source share
3 answers

This is really relative to what you mean by a working paper.

Hypermedia as an application state mechanism will give you an oriented state / resource graph. It is not necessary that these graphs shape the workflow (for example, have a specific start and end point). They can form a loop, have bi-directional links, and more. I assume that this chart somehow escaped from business logic.

If you enable your workflow (a specific path from one point to another using a graph) in the user interface, you make some assumptions about the REST API, so carefully associate your interface with the business logic, so throw REST detection.

In general, mixed workflows (compulsory programming) with REST (declarative programming) are very problematic. The best approach would be to have an adaptive user interface that can allow the user to navigate the network of states instead of holding them back through custom, predefined workflows. In any case, the browser works.

If you really need to have some workflows, you can implement them by creating a chain of interconnected resources and directing the user to the first. In this sense, your first option will be valid, although I believe that the separation of business logic and workflow will be a gray area. Workflows are part of the business logic or, to argue better, are aligned with the business logic.

These opinions belong to me, but a good, relevant article on this topic can be found here: http://www.infoq.com/articles/webber-rest-workflow

+4
source

I just find out what REST really is now, and I hope I'm not from here, but, as I understand it, the client should be responsible for choosing which states to transfer (workflow), so yes. I think that No. 2 is definitely valid. Actually, I would be interested to know how you implement the workflow in your ReST API.

+1
source

REST is access to resources. Question: "What resource"? Most of the answers are that this is pretty low level information.

A composite application or workflow depends on one or more resources.

It is difficult to say that the resource depends on the work process. Impossible. But hard.

When developing a RESTful interface, you have only the available CRUD rules. The most common expectation is that the answer is completely related to your request. When you send an X message, you expect that the only state change will be to create a new X. Do not create X and Y with an optional Z pair.

I would suggest that your second option puts REST in a better context - stateful access to objects.

-2
source

Source: https://habr.com/ru/post/1277499/


All Articles