Using Talend REST Components in A Practical Use Case
Using Talend REST Components in A Practical Use Case
Prerequisites
Recommended training
• Talend Data Integration Basics
• Knowledge Asset - Context Management Common Framework available in Talend Academy
Technical prerequisites
• Minimum system requirements:
Contents
Getting started ..................................................................................................................................................................................................................................... 3
Understanding the essential context variables .................................................................................................................................................................................. 4
REST Client Job overview .................................................................................................................................................................................................................... 5
REST API Job overview ...................................................................................................................................................................................................................... 15
Getting started
In Talend Studio, ensure that the Context Management Common Framework Jobs are available as Reference Projects, by performing the following steps:
1. Navigate to File > Edit Project Properties > Reference Projects.
2. Select CommonFramework from the Project pull-down menu, then select the preferred Branch for the project, in this case, master.
3. Import the rest_template.zip file and extract all of the Jobs and the Contexts group.
The first stage in the process is to add a tPreJob component to the Job, then load the context variables through the common framework
CommonFramework:LoadContext Joblet.
The tREST_1 component consumes the ipify service, which gets the client machine’s IP address, using the provided URL and GET as the HTTP Method.
tExtractJSONField_2 parses the IP address from the JSON field response by setting the Loop Jsonpath query to “$.ip” and using “@” as Json query to
extract the value.
tLogRow_4 component displays the content data structure in the console, in this case, the IP address.
tSetGlobalVar_1 stores the IP address that the next subJob calls or fetches.
The second subJob is analog to the first and contains the same components. However, one component is added to extract the longitude and latitude from
the locality value in the JSON response.
tREST_2 concatenates the URL based on the value stored in the global variable. To get the values from the global variables, cast the value to the
appropriate data type like this: (String)globalMap.get(“my_ip”).
The tExtractJSONField_4 component parses all of the response attributes from the JSON field response.
tLogRow_5 displays the content data structure in the console, that is, the location attribute parsed in the tExtractJSONFields_4 component.
The tJavaRow_1 component splits the location value on longitude and latitude values. The values are required in the next request or subJob.
tSetGlobalVar_2 stores the longitude and latitude global variables that are called or fetched in the next subJob.
The third subJob uses another component, the tRESTClient component, for the request because it has more flexibility and functionality than the tREST
component.
The tREST_2 component reads the URL endpoint, and the “exclude” and “appid” parameters from the context variables. The “lat” and “lon” parameters
are loaded from the global variables.
tExtractJSONField_1 parses all response attributes from the JSON field response.
tLogRow_2 displays the content data structure in the console, in this case, the weather attribute, parsed in the tExtractJSONFields_1 component.
tLogRow_3 displays the content data structure in the console; in this case, the request error generated by the tRESTClient_1 component.
The first stage in the process is to add a tPreJob component to the Job, then load the context variables through the common framework
CommonFramework:LoadContext Joblet.
This subJob is a REST web service that creates a Greeting String from the input parameters.
Gender f or m For simplicity purposes, the rest service supports only Male or Female
Language de, fr, or en For simplicity purposes, the rest service supports only French, English, and German
In addition to the normal flow structure, the Output Flow request comment should contain the word query as a parameter.
tFixedFlowInput is used as a data source for the list of gender values in the supported languages, DE, EN, and FR.
tMap_1 generates the salutation based on the input parameters and the list of values from the tFixedFlow component.
tXMLMap_1 creates the response, and it contains a simple mapping of the status and the response.
However, if the response is successful, the Return status code displays OK (200).