I have an object with fields like ID
, CODE
, NAME
, etc., and it has its own database table with each field. And I am working on implementing the REST API for this object. I want to expose all these fields but also the additional field TYPE
, whose value depends on the CODE
field. If CODE
is in a valid list, it will have the value 'I'
otherwise it will have the value 'C'
(Custom).
In the create operation, the user should be able to specify the TYPE
field and pass the CODE
value accordingly.
My question is: What would be the standard approach to exposing this new TYPE
field so the object can also scale with any new changes? Should I handle it from the backend code only by adding a new field TYPE
and validating and setting its value based on the CODE
value, or should I also add a new column in the table as TYPE
to store the value based on the CODE
value and expose it in the API? I believe this way application and database would have proper mapping between the fields.
Appreciate for any suggestions. Thank you.
TYPE
when the clear rule of its mapping is already present in the back-end ?