I think that the main advantage of the REST API is the provision of a service (usually server-side, not SPA) to third-party REST clients. If you use HATEOAS and other self-describing message solutions such as RDF, REST clients will break much harder due to changes in the REST API. For small projects - "where the REST API has only one consumer - the javascript interface developed by one team" - I donโt think itโs worth having the right REST API. Most people use its simplified version, which I call the CRUD API, and they can be good for these projects.
There may be a 1: 1 mapping between CRUD resources and domain objects of the anemic domain model. If we are talking about real objects (rather than data structures) using not only CRUD methods, then you should translate between resource.verb and object.method, for example:
POST /dogs/{id}/barking -> domain.dog.bark()
If we are talking about more complex things associated with several domain objects and a unit of work (transactions), then you need to add another layer for application services, otherwise you would transfer the entire complex operation, including transaction processing, to the client. In these cases, you translate between resource.verb and applicationService.operation, for example:
POST /dogs/{id1,id2,..}/barking -> dogService.multiDogBark(...) -> UnitOfWork{domain.dogs[ids[i]].bark()}
I think that most developers confuse this approach of CRUD services + an anemic domain system model with the REST services + domain model approach, therefore they ask this question and therefore there are many "REST" structures that add a 1: 1 domain object - a CRUD resource. mapping, or maybe even an ORM object โ mapping of CRUD resources. I find this trend very destructive, and I think the main reason is that developers learn certain technologies only superficially from short articles or question and answer sites instead of reading books and dissertations, where they can gain deep knowledge on a relevant topic. I think this is a problem of the Y + generation, due to which we lose the ability to read long texts due to the use of digital technology. We are driven by instant rewards instead of deferred rewards that give a long text ...
inf3rno
source share