Icon

03.2 Call the prediction workflow via POST request

Calling a prediction workflow deployed as a REST service. Example scenario: The bank wants to allow applicants to calculate their approximate credit score on the bank's website. An applicant needs to provide their data and click the button on the website. The POST request to the prediction workflow is sent and the prediction is returned to the applicant.

Part 1 - Deployment fundamentals

Exercise workflow 03.2 Call the prediction workflow via POST request

Learning objective: In this exercise you'll learn how to apply the workflow deployed as a service.


Workflow description: Calling a prediction workflow deployed as a REST service*. Example scenario: The bank wants to allow applicants to calculate their approximate credit score on the bank's website. An applicant needs to provide their data and click the button on the website. The POST request to the prediction workflow is sent and the prediction is returned to the applicant.

*This workflow demonstrates how to prepare the data for the POST request and make such a request in a KNIME workflow but the POST request can be sent from external clients, e.g., a Postman, Python code, a website etc.


You'll find the instructions to the exercises in the yellow annotations.

Step 2. Make a POST request and predict credit scoring values

  1. Call the deployed workflow via POST request with the POST Request node*

    1. Use the URL you saved in the previous step

    2. In the tab Request body, provide the column JSON (containing the features converted to JSON)

    3. In the tab Authentication, select basic, provide your application id and password


*You can call the workflow via POST request from anywhere - from Postman, from Java code, from Python script, etc. - not only from a KNIME workflow as we do here. This means you can use the workflow deployed as a REST service from anywhere in your production.


Step 1. Get the deployment ID

  1. On the KNIME Hub page of the prediction workflow that you deployed in the previous exercise, find your deployment and click three dots actions button and click Open API docs:

    1. Under the Execution section, expand the POST request section (with .../execution URL)

    2. Click Try it out

    3. Clean up the optional parameters (reset, format, and timeout) and click Execute

    4. Copy the GET request URL from the Request URL field. It should look like this: https://api.hub.knime.com/deployments/rest:<id>/execution

  2. In your profile page, open Settings and Application passwords

    • Create new password, give it a name, and save it while the bar is still green - it won't be possible after you refresh the page.

You can save the predictions for further usage in production and further model monitoring. For example, you save them a timestamp to a database.

Conversion to and from JSON is needed
From table to JSON
Call the prediction workflow deployed as a service
POST Request
New request for prediction
Table Reader
Conversion to and from JSON is needed
From JSON to table

Nodes

Extensions

Links