I have a legacy Java monolithic web application. My goal is to use React on the frontend, keep Java on the backend and add an API for the frontend to use.
My question is how can I write the data validation just once, using it on both the frontend for form validation and on the backend for data validation?
With the API written in java and the data validation written in javascript, is a workable solution to have an intermediate validation proxy API written in javascript+nodejs which then passes validated requests to the java API?
React(js validation) -> nodejs-API(js validation) -> Java-API(no data validation)
Java-API(no validation)
you are assuming there would be always "something" in front of the JAVA API doing validations. You are also assuming that whatever lays in front of Java API has no bugs. Too many assumptions. On the other hand, validations are part of the business. Why decouple them? Why make things so complicated just to reuse a bunch of "if null, if empty, ....". What's the goal? What's the problem to solve?that risk exists even with just the single Java API
yes, but with your design, you have 2 components to test and debug to find where the bug is at.