Icon

3. Input validation

Data retrieval API endpoint

3. Input validation

Step 1. Validate input

  • Paste the following JSON into a Container Input (JSON) node. It is an example of the expected input of the endpoint: {"customer":"Alice"}

  • Convert the JSON input with the JSON to Table node.

  • Add a Table Validator node

    • check for column existence and for data type.

    • Select Deactivate first output port.

  • After execution, only the first output port of the Table Validator should be active.


Step 2. Filter data

  1. Connect the first output of the Table Validator to the Table Row to Variable node.

These nodes are executed only if the input passed the validation test. Use the valid input JSON from Step 1 to activate this branch of the workflow.


Step 4. Generate an error message

  1. Connect the second output of the Table Validator to the Expression node.

These nodes are executed only if the input did not pass the validation test. Use the invalid input JSON from Step 3 to activate this branch of the workflow.


Step 3. Test validation for wrong input

The following JSON is a wrong input that your endpoint could receive.

  1. Copy paste it into the Container Input (JSON) node

  2. After execution, the second output port of the Table Validator node should be enabled.

Invalid input

{"date_from": "2023-01-01",

"status":"shipped"}

Valid input

{"customer":"Alice"}

Step 5. Deploy the REST API endpoint

  1. Upload the workflow to one of your KNIME Hub spaces.

  2. Create a version of the workflow.

  3. Create a service deployment of the workflow.

Step 6. Send a request to the REST API endpoint

  1. Find the endpoint URL.

  2. Send a request to the deployment's endpoint from an external tool

    • Use curl from the command line or Postman.

    • Make sure to authenticate with your application password.

Note. Use a POST request to include in the request body a JSON that does not contain the customer field.
For example: { "status" : "returned" }. The JSON response should contain the error message from Step 4.

Table Row to Variable
Orders
Table Creator
Filter data for the received value
Row Filter
Row Filter
Expression
Receive value to filter for
Container Input (JSON)
Return filtered table
Container Output (JSON)
JSON to Table
CASE Switch End
Table to JSON
Table Validator
Column Filter

Nodes

Extensions

  • No modules found

Links