0% found this document useful (0 votes)
49 views19 pages

Using Talend REST Components in A Practical Use Case

Using Talend REST Components in a Practical Use Case

Uploaded by

rodrigofjorge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views19 pages

Using Talend REST Components in A Practical Use Case

Using Talend REST Components in a Practical Use Case

Uploaded by

rodrigofjorge
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Using Talend REST Components in a Practical Use Case – Talend Solution Templates

Using Talend REST Components in a Practical


Use Case
Introduction
Talend offers multiple possibilities to create and consume REST Services. Developers can create their APIs as Routes or as Jobs. This solution template shows
you how to create REST API Jobs, including one that uses the OpenWeatherMap API Guide to consume REST API client services, and another that calls REST
API web services.
For use in conjunction with the REST_components.zip – Talend project.

Prerequisites
Recommended training
• Talend Data Integration Basics
• Knowledge Asset - Context Management Common Framework available in Talend Academy

Technical prerequisites
• Minimum system requirements:

OS CPU RAM SSD Disk Size

Windows/Linux/Mac Intel i7 Processor 4 Cores or equivalent 8 GB 50 GB

• Talend Data Integration platform Studio version 7.3.1 (on-premises or cloud)


• Access to the Context Management Common Framework.zip and REST_components project.

Copyright Talend 2020 1


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

Contents
Getting started ..................................................................................................................................................................................................................................... 3
Understanding the essential context variables .................................................................................................................................................................................. 4
REST Client Job overview .................................................................................................................................................................................................................... 5
REST API Job overview ...................................................................................................................................................................................................................... 15

Copyright Talend 2020 2


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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.

The project is stored in the Referenced project section of the Repository.

3. Import the rest_template.zip file and extract all of the Jobs and the Contexts group.

Copyright Talend 2020 3


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

Understanding the essential context variables


The REST client Job requests three REST APIs; the last one uses the OpenWeatherMap API service. Using this service requires adding the appid context
variable and adapting the exclude (optional) context variable. The context variables are loaded to the Job by adding the context load common Joblet in
the PreJob section of the Job.

Copyright Talend 2020 4


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

REST Client Job overview


This section describes the overall Job flow for the job_rest_client Job.

Copyright Talend 2020 5


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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 next stage in the Job flow is to add three subJobs.


The first subJob requests the machine's IP address where the client is located and saves it in a global variable.

Copyright Talend 2020 6


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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.

Copyright Talend 2020 7


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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.

Copyright Talend 2020 8


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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”).

Copyright Talend 2020 9


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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.

Copyright Talend 2020 10


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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.

Copyright Talend 2020 11


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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.

Copyright Talend 2020 12


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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.

Copyright Talend 2020 13


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

tLogRow_3 displays the content data structure in the console; in this case, the request error generated by the tRESTClient_1 component.

Copyright Talend 2020 14


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

REST API Job overview


This section describes the overall Job flow for the job_rest_api Job. This Job has only one subJob.

Copyright Talend 2020 15


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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.

Parameter Possible Values Description

Name Alphanumerical String Example: Mustermann, Schmidt, and others

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

Request example: http://localhost:8088/greeting?name=Mustermann&gender=m&language=en


The tRESTRequest_1 component is configured with the REST Endpoint, http://localhost:8088/, and uses only one GET method, “greeting” to produce
the JSON file.

Copyright Talend 2020 16


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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.

Copyright Talend 2020 17


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

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.

Copyright Talend 2020 18


Using Talend REST Components in a Practical Use Case – Talend Solution Templates

The tRESTResponse_1 component creates a response. It is set to Bad Request (400).

However, if the response is successful, the Return status code displays OK (200).

Copyright Talend 2020 19

You might also like