Uncategorized

Talend REST API – As Microservice – Spring Boot Application

Today we will be show casing an example

  1. How to create REST API – CRUD operations
  2. REST API Documentation using Swagger
  3. API best practices
  4. Deploying job 2 modes
    1. Karaf Mode
    2. Spring Boot Micro service and deploy on AWS EC2 instance
  5. Debugging
  6. Response as JSON and XML

Step 1 : Creating REST API – Get Call

Prerequisites :

Make sure MySQL is running

i’ve created a database and also created a table called user_phone with few columns.

Now lets display the above values as XML and JSON format using API. Lets create an end point with Accept or Content-Type = application/json or application/xml

Talend Job

components used – tRestRequest – This will allow you to create API Request with Web protocols like GET, POST, PUT, HEAD, DELETE, PATCH and OPTIONS.

You can create your own flows , you can create your url pattern and select type you want to produce like XML or JSON.

By detault talend gives you API REST ENDPOINT like localhost:8088, if you are using OSGI it will be deployed under services ( karaf container )

If you are building as micro service -> you can define your own port number and expose it.

In your tXML file

in my MYSQL , we have 5 columns but i wanted to display only 2 columns in my output.

use tXMLMap to filter columns. You have to use “All in one” = “true” to show all records

You need to loop in such a way all elements come under customer.

last component is tRestResponse

Which which give you 200 API.

Currently i’m running karaf container with Talend run time server installed. Ill be seeing my services page like this

http://localhost:8040/services

Since i exposed this service + enabled swagger documentation

I should able to see the service and auto documentation like
We can see a 200 successful message.

Same thing we can try testing with post man application

we can test with JSON and XML by passing parameters like Accept and content-type

Note : in order to hide root element you should select the following check box in response component

Now lets see how we can build this as micro services using Spring boot

when you right click on job and say build – you should see couple of options

You can select microservice – spring boot for ESB

This will create a jar file. Using that jar file you can run on any platform like java -jar savedname.jar

As simple as possible.

I’m running this job on Talend cloud

I can see all the stats like number of request, total number of request and others. This will be really useful.

Leave a comment

Talend Best Practices

Feel free to reach out to us with any questions at : solutions@thinkartha.com