DEV Community

Discussion on: How close to the data you like to have your business logic operations?

Collapse
 
kspeakman profile image
Kasey Speakman

I typically resign myself to duplicating validation. I think this is ok (but annoying), because really validation is for a different purpose. UI validation is to help the user make the right choices. API validation is to make sure that requests off the wire make sense. They are often so close that literally the same validation could be used, especially in CRUD scenarios. But I do sometimes find variances where if I had applied DRY it would be harder than just validating separately. It is a fine line. :/

Collapse
 
courier10pt profile image
Bob van Hoove

Good to hear it's not uncommon to have duplicate validation :) Thanks for sharing your insight.

Collapse
 
andreujuanc profile image
Juan C. Andreu

UI Validation does not cover all the validations necessary. So, it's pretty common to have them "redundant" through deeper layers.
Example: "name" is mandatory for the UI to have a quick feedback to the user about his small mistake leaving it empty, but the API almost must have this validation as well. But then, suddenly, a wild mobile app appears, and you need to implement this validation again for offline use!

Thread Thread
 
kspeakman profile image
Kasey Speakman

Yep, it's one of those areas where there are significant trade-offs to set it up in a unified manner. It will be worth it in some cases (especially where you have a lot of different clients) but not in others.