Consider the following scenario:
- If the user isn’t registered in the database, register them. Return their ID.
- If the user is in the database, return their ID.
The API endpoint for this may look something like
The consumer of the API does not want to first
GET a userId and, if
null is returned, then
Adhering to CQRS architecture and respecting REST design, if we have the
POST invoke a Query first, it seems odd to have a
POST that is statistically more likely to be making database queries and returning results. This Query-invoking-
POST is more often than not acting as a
But if we decide to have the
POST invoke a Command first, it seems like an anti-pattern to have that Command exist where it is, more often than not, just performing a Query – that is, checking for the user registration in the DB and possibly returning the ID if found, never actually creating, updating, or deleting something.
What is practical approach to this situation?