What I want to achieve?
I want to define API with date parameter:
/api/public/mydatapagemethod?dateFrom={dateFrom}
The API works fine when the parameter is in correct format (yyyy-MM-dd
or yyyy-MM-ddTHH:mm:ss
). If the format is not correct, then it leads to server internal error which is not something you would like to show to the end API user.
Validation Rule
I have tried to use Input Validation Rule which return readable exception but the context of the rule is empty when I trace it (<ROOT />
). So it means it is designed only for request body but not parameters.
Is there any way how to validate API input parameters? I guess at the moment the only way is to create Workflow Method with check rule. I did it and it works as expected, I pass the parameter to the string context and then verify inside workflow using (Task) check rule step inside the workflow.
Suggestions?
It is not a lot of effort to create Workflow method, validate parameters and call Load method to load data. But I think whether it should be even simpler?
For example define data type of API parameter or add validation rule directly to the parameter and validate it as a Simple Context (/ROOT/value
).
That would bring parameters’ validation to simple Data Page Workflow without need to define Workflow method but only define simple validation rules for parameters.
This is just suggestion to streamline modeling of API, but nothing needed as the solution is available using Workflow method to load data structure.