In my project using DDD methodology.
The project has the aggregate(entity) Deal. This aggregate has many of use cases.
For this aggregate I need to create a rest api.
With standard: create and delete no problem.
1) CreateDealUseCase(name, price and many another params);
POST /rest/{version}/deals/
{
'name': 'deal123',
'price': 1234;
'etc': 'etc'
}
2) DeleteDealUseCase(id)
DELETE /rest/{version}/deals/{id}
But what to do with the rest of the use cases?
- HoldDealUseCase(id, reason);
- UnholdDealUseCase(id);
- CompleteDealUseCase(id, and many another params);
- CancelDealUseCase(id, amercement, reason);
- ChangePriceUseCase(id, newPrice, reason);
- ChangeCompletionDateUseCase(id, newDate, amercement, whyChanged);
- etc(total 20 use cases)...
What are the solutions?
1) Use verbs:
PUT /rest/{version}/deals/{id}/hold
{
'reason': 'test'
}
But! Verbs can not be used in the url(in REST theory).
2) Use the completed state(which will be after the the use case):
PUT /rest/{version}/deals/{id}/holded
{
'reason': 'test'
}
Personally for me it looks ugly. Maybe I'm wrong?
3) Use 1 PUT request for all operations:
PUT /rest/{version}/deals/{id}
{
'action': 'HoldDeal',
'params': {'reason': 'test'}
}
PUT /rest/{version}/deals/{id}
{
'action': 'UnholdDeal',
'params': {}
}
It is difficult to handle in the backend. Moreover, it is difficult to document. Since 1 action has many different variants of requests, from which is already dependent on specific responses.
All solutions have significant drawbacks.
I have read many articles about the REST on the internet. Everywhere only a theory, how to be here with my specific problem?
/rest/{version}/dealsheld/
,/rest/{version}/dealscompleted/{id}
, etc. Since one would need to know which state you are dealing with in any event. Would a scheme such as that make sense? – Cologne