I am building a REST service over CQRS using EventSourcing to distribute changes to my domain across services. I have the REST service up and running, with a POST endpoint for creating the initial model and then a series of PATCH endpoints to change the model. Each end-point has a command associated with it that the client sends as a Content-Type parameter. For example, Content-Type=application/json;domain-command=create-project. I have the following end-points for creating a Project record on my task/project management service.
- api.foo.com/project
- Verb: POST
- Command: create-project
- What it does: Inserts a new model in the event store with some default values set
- api.foo.com/project/{projectId}
- Verb: PATCH
- Command: rename-project
- What it does: Inserts a
project-renamedevent into the event store with the new project name.
- api.foo.com/project/{projectId}
- Verb: PATCH
- Command: reschedule-project
- What it does: Inserts a
project-rescheduledevent into the event store with the new project due date.
- api.foo.com/project/{projectId}
- Verb: PATCH
- Command: set-project-status
- What it does: Inserts a
project-status-changedevent into the event store with the new project status (Active, Planning, Archived etc).
- api.foo.com/project/{projectId}
- Verb: DELETE
- Command: delete-project
- What it does: Inserts a
project-deletedevent into the event store
Traditionally in a REST service you would offer a PUT endpoint so the record could be replaced. I'm not sure how that works in the event-sourcing + CQRS pattern. Would I only ever use POST and PATCH verbs?
I was concerned I was to granular and that every field didn't need a command associated with it. A PUT endpoint could be used to replace pieces. My concern though was that the event store would get out of sync so I just stuck with PATCH endpoints. Is this level of granularity typical? For a model with 6 properties on it I have 5 commands to adjust the properties of the model.