Talend ESB RESTful Service

10:40 AM

This post is in continuation with Realtime Response using Talend ESB, here I will show you how to create and run simple REST API. To create MyFirstAPI job I have used TOS ESB v.6.1.1 tRESTRequest_1 will receive a GET request from browser using REST Endpoints and URI pattern "http://localhost:8088/talend/{action}" where action is the query parameter which could be anything and we can get value from URI using this query parameter to perform certain logic on server. In this simple example I am using this query parameter {action} to determine valid/invalid response of API. Screenshot 2016-01-25 03.08.05.png tFlowToIterate will load a global map variable "requestAction" from the request url. Screenshot 2016-02-01 01.03.28.png If1 will send Valid response only when globalMap requestAction is equals to valid.
((String)globalMap.get("requestAction")).equals("valid")
Screenshot 2016-02-01 01.07.11.png In tFixedFlowInput > Edit Schema Create Columns status and message and set status values as "valid" and message value as "Request is Valid". Screenshot 2016-02-01 01.14.22.png In tXMLMap pass status and message to root Element of response. Screenshot 2016-02-01 01.18.49.png In tRESTResponse set Return Body Type as Document and Return Status Code as OK(200) Screenshot 2016-02-01 01.22.31.png Now check for any other action to send invalid response paste below condition in If2. !((String)globalMap.get("requestAction")).equals("valid") And in tFixedFlowInput_2 set status as "invalid" and message as "Request is invalid" Screenshot 2016-02-01 01.29.56.png Now Run job and Talend ESb will open endpoint from tRESTRequest. http://localhost:8088/ Screenshot 2016-02-01 01.32.31.png You can call MyFirstAPI job using REST endpoint and URL Pattern from web browser. http://localhost:8088/talend/valid Screenshot 2016-02-01 01.40.50.png  

You Might Also Like

0 comments

TalendTricks.com. Powered by Blogger.