Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4118

Should a non-form field whose value depends on another form field in some scenarios be set in API backend using logic or be sent from UI to API?

$
0
0

Let's say I have a field as a dropdown on my UI form (POST). If user selects a specific value of fruit, then a different field related to the whole object entity should also get set with a predefined value. This different field is not part of my UI form, so it is currently also not part of the POST API.

For example, say the dropdown on UI form is 'fruit' and if user selects 'Mango' there, then a different field 'fruitType' should be set with defined value of 'sweet'. For other values of 'fruit', 'fruitType' should not get set.

Should this non-form field 'fruitType' be set directly in the backend based on the logic for 'fruit'='Mango' or should this logic be part of UI and UI should send 'fruitType' as a new parameter to API?

In the second approach, API will also need to have validation, thereby duplicating the mapping logic in backend too. So, I am leaning towards first approach. However, I wonder if that (first approach) will make things opaque for other developers.


Viewing all articles
Browse latest Browse all 4118

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>