I'm developing a new service in a micro-services environment. This is a REST service. For simplicity, let's say that the path is: /historyBooks
And the POST method for this path creates a new history book.
Let's assume that a history book covers one or more eras in history.
For brevity, let's assume we have only the following eras of human history:
- Ancient
- Post Classical
- Modern
In my code, I'd like to represent them in an enum
.
The method's body (the payload) is in JSON format, and should include a field name eras
. This field is a list of era
values, that this book covers.
The body may look like:
{
"name": "From the cave to Einstein - a brief history review",
"author": "Foo Bar",
"eras": ["Ancient", "Post Classical", "Modern"]
}
In this specific service, the business logic is:
If no eras provided in the input, then this book is considered to cover all eras.
In the API review, a suggestion was made:
Include another value, ALL
, for the eras enum, to explicitly indicate that all of the eras are covered.
I think it has some pros and cons.
Pros:
Explicit input
Cons:
If two items in the list are provided, say ALL
and Ancient
- what will be taken from the application? I guess that ALL
should override the other values, but that's new business logic.
If I run a query, for books that cover specific era(s), how would I represent a books that cover all eras? If ALL
is also used for the output (using the same logic), then it's the consumer's responsibility to interpret ALL
as ["Ancient", "Post Classical", "Modern"]
.
My Question
I think that having the new ALL
causes more confusion than not having it at all.
What do you think? Would you add this ALL
value or keep your API without it?