I am struggling with architecture on a new project. I am using the following patterns/technology.
I belive this provides some great separation and should help keep a very complex domain from growing into a giant set of services that mix queries with other business logic.
I expected this to be much different but I wasn't around to keep things on track.
Finally my questions are this...
I would have liked to see
PUT Person (CreatePersonCommand) but then I realized that isn't restful either is it? the put should be a person entity not a command.
Can I make CQRS and REST service work together or am I going about this all wrong?
How do I handle service methods that don't fit into a REST model. I am not performing CRUD on the object but rather executing some business logic. I.E. I don't want the UI to be responsible for how a shipment is "unshipped" I want the service layer to worry about that.
So instead of using
You'd have a "search" (noun) resource
I've always felt that's kind of a word game, but it does has the benefit of keeping your semantics resource oriented.
it's just PUT to
...the call is the same, it's just that you're using the HTTP verb (PUT) instead of duplicating that in the resource name.
CQRS is about splitting up your writers from your readers. It would be fair game under both CQRS and REST to add some resources that only accept POST -- using the "data processing" clause for POST provided in the HTTP spec. POST data for processing, then GET the resulting resources.
But as long as your resource names boil down to nouns rather than verbs, you can keep all the purists happy.
A Command name is just a combination of action + target. You're concatenating those to create your Command names "ActionTargetCommand".
the target goes in the base URI
the action becomes the method or else implied from the query string
and Command just goes away as redundant
You either need to make your action one of the HTTP methods, or else turn the resource into a processor noun.
One one level, it's just renaming to suit a resource-oriented paradigmn, but on a deeper level is a matter of splitting the commands into those covered by the HTTP methods, and others into processing nouns.
/Persons?name="Thomas". This is saying "Give me a list of all Persons whose
nameis "Thomas". — Dec 30, 2019 at 21:02
External links referenced by this document: