rest - RESTful API: Where should I code my workflow? -
i developing restful api. first api, first big coding project. such, i'm still learning lot architecture etc.
currently, have api setup in following layers:
- http layer
- resource layer
- domain model / business logic layer
- data access / repository layer
- persistent storage / db layer
the issue have run @ moment need put workflow objects / managers? workflows, mean code evaluates next step required end user. example, e-commerce workflow. user adds item basket, checks out, fills in personal details, pays. workflow responsible deciding steps next, steps not allowed. example, user couldn't cause errors in api trying pay before have entered personal details (maybe recall uri payments , try skip step). workflow check see previous steps had been completed, if not, not allow payment.
currently, workflow logic in resource layer. using hypermedia links present workflow user e.g. providing 'next step' link. problem have resource layer top level layer, , more aligned presentation. feel needs know underlying domain model evaluate workflow i.e. need know has check personal_details entity before allowing payment.
this leads me thinking workflows belong in domain model. make lot more sense, workflows part of business logic , think therefore best placed in domain layer. after all, replace resource layer else, , still need underlying workflows.
but problem workflows required knowledge of several domain objects complete logic. feels right maybe goes in own layer? between resource , domain layer?
- http layer
- resource layer
- workflow layer
- domain model / business logic layer
- data access / repository layer
- persistent storage / db layer
im wondering if had other views or thoughts around this? said, have no past application experience know workflows should placed. im learning first time want make sure i'm going right way.
links articles or blogs cover appreciated. love reading on different implementations.
edit
to clarify, release hateoas allows client navigate through 'workflow', there must in api knows links show i.e. defining workflow allowed. presents workflow related links in resource, additionally validates requests in sync workflow. whilst agree client follow links provided in resource, danger (and beauty) of rest, uri driven, there nothing stopping mischievous client trying 'skip' steps in workflow making educated guess @ uri. api needs spot , return 302 response.
the answer question has taken me fair bit of research, 'workflow' part has nothing rest @ , more application layer.
my system had application logic , rest api tightly coupled. solved problem refactoring reduce coupling , workflow lives within context of application
Comments
Post a Comment