Today we will be show casing an example
- How to create REST API – CRUD operations
- REST API Documentation using Swagger
- API best practices
- Deploying job 2 modes
- Karaf Mode
- Spring Boot Micro service and deploy on AWS EC2 instance
- Debugging
- 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.
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.
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
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
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