3 ms·
Quite often, using nouns actually improves your architecture (and your Ubiquitous Language[0]). This design constraint is often one that pushes you in the right
by berkes 5y ago
Quite often, using nouns actually improves your architecture (and your Ubiquitous Language[0]). This design constraint is often one that pushes you in the right direction, but you have to allow it to push you.
E.g. the classic "I want to archive this ticket". Three common approaches:
POST/PUT /coupons/1337/archive
PATCH /coupons/1337 { archived: true }
POST/PUT /coupons/1337/archivals
Designer now gives up. The second option is technically often the easiest (esp with CRUD frameworks like Laravel or Rails) but design wise by far the worst. The first is RPC-style and the last is suffering from what parent describes
> As a result, you end up with rather CRUDdy noun-oriented systems that don't really flow
What we see, however, is that our UL is lacking. What is it that we really do. What do we end up with?[1] We might "copy it to the archives" or "relocate it to the archives" etc, depending on your business case and domain details. We request a "relocation", which, when resolved, results in an "archived ticket".
POST /archives/tickets/ { ...the entire ticket }
or
POST /tickets/1337/relocations
It now adheres to REST, better describes the domain language, is consistent and flows quite alright. EDIT: the latter, for example, communicates that this may take a while (async), results in the ticket being moved elsewhere and the original one probably redirecting to the new. The former communicates clearly that we are making a copy or snapshot of the ticket in the archives.
But there will always be cases where the verb makes more sense or adheres much better to the UL and domain. In such cases, one can still be resource-full and REST-full without introducing awkward nouns. E.g. in an CQRS setup, we interface with Commands. We can then request commands: `POST /commands/archive_ticket_command/` for example.
---
[0] https://www.martinfowler.com/bliki/UbiquitousLanguage.html https://www.martinfowler.com/bliki/UbiquitousLanguage.html
[1] Sidenote: I try to avoid words that are both a nound and verb. Like "archive". To archive vs In the archive: this causes ambiguity.*