0

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?

MarioDS
  • 12,895
  • 15
  • 65
  • 121
  • 1
    I saw this done in different ways, some was implementing validation only services and called on every validation properties (c and others). Others used the "dry-run" requests with a value (say draft=true) which does not save the object unless that value is false.I'm not sure what would be the best solution but I can't think of any differences that would make one better than the other. – Anddo Oct 06 '17 at 13:36
  • [This could be useful for you](https://stackoverflow.com/questions/10645133/restful-api-what-method-header-combo-to-use-for-validation-only). Also see [this](https://stackoverflow.com/questions/33242682/how-to-design-a-restful-api-that-queries-info-about-a-verb-e-g-a-potential-pos). – Anddo Oct 06 '17 at 13:45
  • @Anddo those are very useful links that I have missed despite my thorough search efforts. Thanks! – MarioDS Oct 06 '17 at 13:46

0 Answers0