I have a REST API and a desktop client consuming that API. One of the screens in the desktop client is the front-end for "building" or "constructing" an instance of a fairly complex entity.
Let's call this entity X
it has complex properties A
, B
and C
. Complex meaning, their datatypes make no sense as an entity but consist of several primitive properties.
The client should be able to POST the newly created instance of X
to the server but property C
has validation logic and the button that enables creation should be disabled before C
has valid values.
How do architect a REST API so you could validate C
in the context of creating X
, using server-side validation code that you don't want to repeat in the client?
You cannot just POST X
to check whether it was valid, because if it was you have now saved your instance of X
and maybe the client was not done editing. All you wanted to know is whether the fields on the screen are valid.
Some people appear to implement the concept of "dry-run" POSTs to see if validation would fail, but not save anything if it doesn't.
I was just wondering if there are better solutions?