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.
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.
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.
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.
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.
Clicking the run tab starts the job. Parallelly, we must run the HTTP listener from Postman by clicking the send button.
After successful run job is ending with 200 ok status.
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.