Scenario 2: Updating user information by interacting with a RESTful service - 6.1

Talend Components Reference Guide

EnrichVersion
6.1
EnrichProdName
Talend Big Data
Talend Big Data Platform
Talend Data Fabric
Talend Data Integration
Talend Data Management Platform
Talend Data Services Platform
Talend ESB
Talend MDM Platform
Talend Open Studio for Big Data
Talend Open Studio for Data Integration
Talend Open Studio for Data Quality
Talend Open Studio for ESB
Talend Open Studio for MDM
Talend Real-Time Big Data Platform
task
Data Governance
Data Quality and Preparation
Design and Development
EnrichPlatform
Talend Studio

This scenario describes a three-component Job that updates the information of a list of users to a remote database through a REST service using the HTTP POST method. When executed, the Job displays the client-server message exchange information on the Run console.

The user information to be updated to the server is stored in a CSV file, which looks like the following:

id;first_name;last_name
1;John;Smith
2;Martin;Reagan
3;James;White
4;Jenny;Jackson
5;Robert;Thomson

Prerequisites:

If you are a Talend ESB user, create a Job as described in Scenario 3: REST service accepting HTTP POST requests and run the Job as a REST server to expose a REST service that accepts HTTP POST requests. Upon execution of the Job, the console displays the service implementation information, including the service endpoint URL, which is http://localhost:8045/users in this example. If you enter http://localhost:8045/users?_wadl in your Web browser, you should see the service definition information like the following:

If you are not a Talend ESB user, then you need to get the service-related information from your REST service provider including the URL, the resource path, and the data structure, and make necessary modifications in the scenario configurations accordingly.

Setting up the Job

  1. Create a Job and add the following components by typing their names in the design workspace or drop them from the Palette:

    • tFileInputDelimited, to read user information of a local file,

    • tXMLMap, to adapt the input structure to the REST service structure, and

    • tRESTClient, used to call the REST service to send data to the remote database.

  2. Connect the tFileInputDelimited to the tXMLMap using a Row > Main connection.

  3. Connect the tXMLMap to the tRESTClient using a Row > Main connection, and give the output flow a name, request in this example.

  4. Label the components to best describe the actions to perform.

Configuring the components

Configuring the input data and the structure mappings

  1. Double-click the tFileInputDelimited component to open its Basic settings view.

  2. Specify the input file in the File name field, fill the Header field with 1 to skip the header row, and keep the rest parameters as they are.

  3. Click the [...] button next to Edit schema to open the [Schema] dialog box, and edit the input schema as follows:

    • id, type Integer, 2 characters long, set as the key column

    • first_name, type String

    • last_name, type String

  4. Double-click the tXMLMap component to open the Map Editor.

  5. Rename the root node in the output table: right-click the node, select Rename from the contextual menu, and specify a new name in the pop-up dialog box, user in this example.

  6. Select all the three columns in the input table and drop them onto the user node, and select the Create as sub-element of target node option from the pop-up dialog box to set these columns as sub-elements of the user node. When done, click OK to validate the mappings and close the Map Editor.

Configuring the service call

  1. Double-click the tRESTClient component to open its Basic settings view.

  2. Fill the URL field with the URI location where the REST service is accessible, "http://localhost:8088/users" in this example.

  3. In the Relative Path field, enter the resource path, "/post/" + row1.id+ "/" + row1.first_name + "/" + row1.last_name in this example. This will send the data from the input row to the server end via the resource path.

  4. From the HTTP Method list, select GET to send an HTTP request for retrieving the existing records.

    From the Accept Type list, select the type the client end is prepared to accept for the response from the server end, XML.

  5. In the Advanced settings view of the tRESTClient component, select the Log messages check box to log the message exchange information with the server.

    Leave the rest of the settings as they are.

Running the Job and checking the result

Press Ctrl+S to save your Job, and press F6 to execute it.

The console displays the client-server exchange information:

The console of the server Job displays the exchange information and the database update result.