Validating the API request
Click here to get the flow definition for this tutorial..
The API created in previous steps successfully receives two query parameters name
and surname
but they are not required. In this tutorial they are converted to required parameters and flow is updated to validate them.
Requiring query parameters
Update the form to make the query parameters required and save the operation:
The query parameters are now shown as required in the Swagger API tool, but they are not yet validated by the flow. Execute the API from an external tool and you will notice that it is still possible to omit the query parameters.
Enabling validation in the flow
The next step is to enable validation for the incoming request and reject the request if the query parameters are missing. This is achieved by adding a Request validation Step to the flow.
- Navigate to the
/transformUser
flow and attach a Request Validation step at the beginning of the flow and save it. - Alternatively you can import the flow attached to this tutorial.
Do not specify any additional properties for the Request Validation step. It will automatically know how to validate the incoming request based on the API definition. Using a custom validation schema is covered later.
Testing that parameters are validated
// Code: 200
{ "fullName": "Joe Test", "requestTime": "2023-07-06T06:20:16.735Z", "name": "Joe", "surname": "Test" }
// Code: 500
{ "statusCode": 500, "message": "Error in flow 'transformUser' : Request Schema validation error" }