Posting Data using the POST Method
Web Service Configuration for Posting Data using the POST Method
The following sample lists the steps to configure the finance Web service for posting data to it using the POST HTTP method.
Canvas enables you to post data to the Web service through auto generated forms of Request Modeler and self-designed forms after mapping the model ID to them. Whether the forms are auto generated or self-designed, the submission sequence will be through Request Modeler. Ensure to select the correct Web service data source while creating the request in the Request Modeler. For more information, refer Configuring Request Modeler.
Details of the sample web service
URL: http://localhost:9005/ShreeFinancials/rest/finance/postfetch
Domain name: http://localhost:9005/
Context root: /ShreeFinancials/
Part of Web service URL: /rest and /addProduct
Web service: finance
When you create the connection, ensure that the following fields are configured in the Create New Connection screen for the base URL as follows:
- Authentication Type - No Authentication
- JSON Configuration for Request panel – Please refer JSON Configuration for Request.
To configure the Web service, perform the following steps:
- Perform steps 1 to 3 mentioned in the Web Service Configuration for Fetching Data using the GET Method.
- In the Create New Data Source page, configure the property fields in the Mandatory Configuration tab as follows:
- Connection Name: This is a non-editable field and displays the unique name provided by you for the connection. For example, WSCONNECTIONPOST.
- Data Source Name: Provide a unique data source name. For example, WEBSERVICEPOSTING.
- Relative part of the URL: Provide the relative URL. For example, ShreeFinancials/rest/finance/addProduct.
- Communication App ID: Select the Rest POST JSON Gateway option in this field. For more details on this field, refer the Field Descriptions.
- In the Response Data Mapping panel, provide inputs in the fields as follows:
Column Root: Provide the hierarchical path to the element that contains the JSON array of data from the Web service response. For example, for the finance Web service, the JSON response is as follows:
{ "STATUSCODE": "SUCCESS" }
Therefore, the root element will be $ as the response is starting from the root path.Value Select Expression: For the finance Web service, provide the value select expression as follows:
#getStatus({'status':'STATUSCODE','Message':'MESSAGE'})#
As we are posting data to the finance Web service, we are expecting a response status and a detailed message from the Web service. The fields in which the status and the message are passed will differ for each Web service. Hence, use the getStatus() method to define the status and message fields for Canvas to parse the Web service response. Here, 'status' and 'Message' are the JSON field names in which the actual field names 'STATUSCODE' and 'MESSAGE' are sent respectively.
View Column Id: Provide the value STATUS in this field.
In the case of posting to a Web service, the value STATUS in the View Column Id field is an indication to Canvas to identify the value select expression to parse the posting Web service status response. Therefore, the value provided in this field must always be STATUS, irrespective of the Web service being configured.
Unlike the GET or POST method to fetch data, we do not have to provide the View Column Id value – STATUS in the Column ID field in App Designer or the View Item ID field on the Create View Definition screen. This is because we are posting data to the Web service through a form. We configure only the status response from the Web service as the value select expression for posting data.
In the Request JSON Configuration field, specify the JSON as shown in the following screen shot:
Refer Passing Data as Header Parameter in Request to get more information on sending data as header parameter to the request.- The query param concept applies only to Web services using the GET HTTP method.
- When the POST method is used for Web service configuration, the payload is sent in the body of the request in JSON format.
{ "productDesc": "$form.productDesc", "productCode": "$form.productCode", "transactionAmount": "$form.transactionAmount", "gcif": "$form.gcif", "userId": "$form.userId", "transactionRefNo": "$form.transactionRefNo" }
Here, $form.<fieldname> indicates that these fields will be available in the forms generated through Request Modeler for the data to be published to the Web service.
The following screen shot shows the Request JSON Configuration field with the JSON configuration:
When you hover over the confirmed JSON, the following icons can display:
: To enable or disable a field in the JSON model condition.
: To add a field in the JSON model condition.
: To delete the JSON Model condition from the Request JSON Configuration field.
- In the Create New Data Source screen, configure the property fields in the Additional Configuration tab as follows:
- Service Type: The field is auto-populated with the POST option when the Rest POST JSON Gateway option is selected in the Communication App ID field. For more information on this field, refer the Field Descriptions.
- Instruction Class: This field is auto-populated with the default Java instruction class com.intellectdesign.canvas.defaultviews.DefaultRestServiceInstruction. For more information on this field, refer the Field Descriptions.
- Click Save.
Once the data source is successfully created for the connection, you can do any of one of the following:
Create a request in Request Modeler to auto generate a form for publishing data to the Web service.
OR
Create a form in form designer, create a request by mapping the correct Web service data source and map the Request Model ID to the form. When you are designing the form ensure that the form item IDs exactly match with the Web service field names. For more information, refer Configuring Request Modeler.
The following screen shots show the form made available in the Modelhouse application to publish data to the finance Web service.
- The auto generated form is available through a menu called Loan Types on the Payments Workspace.
- The form launches when the Loan Types workspace menu is clicked. The details are entered and the form is submitted.
- A confirmation message displays on the successful submission of the form.
- The details entered in the form get posted to the finance Web service.