This article covers the configuration of tRestRequest, tRestResponse and How can we create the HTTP listeners using postman.
Create a job in the Talend tool (it can be Talend ESB or Talend Data fabric). Once you have created a job, place tRestRequest, tjavaRow component, and tRestResponse in the designer.
![Capture1](https://blogs.perficient.com/files/Capture1-11-640x198.png)
Talend Designer – job created and component placed.
Once you have placed all the components, you can configure the tRestRequest component as mentioned below. For this configuration, you must provide the endpoint URL and Mapping. This URL must match the Postman URL that we need to create it.
![Picture2](https://blogs.perficient.com/files/Picture2-136.png)
Talend tRestRequest settings
![Capture3](https://blogs.perficient.com/files/Capture3-3-640x181.png)
HTTP listener (name and place are query parameters)L
![Picture4](https://blogs.perficient.com/files/Picture4-111.png)
HTTP listener (body)
As mentioned above postman collection we need to provide the URL(eg: http://localhost:8088/api). Once postman setup done, we need to add the schema. for that just click the output flow(here, details) add the schema as mentioned below. In Schema tab we have to give comment as query for query parameters.
![Picture5](https://blogs.perficient.com/files/Picture5-91.png)
Schema – by clicking the 3 dot in Output flow
HTTP Method is mentioned a POST here so we can give HTTP Verb as POST. After configuring the tRestRequest,nn here it is just printing the message. System.out.println(“”) -> Syntax for printing any messages.
![Picture6](https://blogs.perficient.com/files/Picture6-84.png)
Configuring tJavaRow
Then, tRestResponse has to be configured by providing the datatype of the message or payload that we are going to get from the tJavaRow Component. So here it is: string. After a Successful run, it will show 200 OK responses in Postman.
![Picture7](https://blogs.perficient.com/files/Picture7-77.png)
Configuring tRestResponse
Clicking the run tab starts the job. Parallelly, we must run the HTTP listener from Postman by clicking the send button.
![Picture8](https://blogs.perficient.com/files/Picture8-66.png)
Started the job. Now the provided endpoint is started running.
After successful run job is ending with 200 ok status.
![Picture9](https://blogs.perficient.com/files/Picture9-56.png)
HTTP listener Response as details received and status as 200Ok
![Picture10](https://blogs.perficient.com/files/Picture10-43.png)
The message or payload from listener is displayed here.
How to call more than one API endpoint using rest components
It is like creating one API listener. The tRestRequest configuration is given below. There are 2 Output flows mentioned in the REST API Mapping. Here, the URI Pattern must be declared. Those are “/details” and “/projects.” While creating the endpoint, we have to use the whole URL, like “http://localhost:8088/api/details” and “http://localhost:8088/api/projects.” These two are POST methods.
http://localhost:8088/api/details?name=abc&place=xyz
- http://localhost:8088/api – is a common API endpoint for both listeners.
- /details – is URI pattern
- ?name=abc&place=xyz – is Query params
So this is how we need to create the API endpoint in Postman.
The next part is Java components. I have used those components just for printing the body using print statements. (System.out.println(input_row.body);).
Below “if condition” is used to trigger the respective endpoint flow.
Extracting the URI global variable from the tRestRequest pattern and equating it with the specific endpoint name. Based on the URI pattern, the job flow will trigger. Then, a response is sent to the listener via tRestRequest.
This is about creating listener for two endpoint.