Creating Rest service in Tibco BW using RestJSON Plugin with Post Method
In this post I am going to discussing how to create simple rest service in tibco business work using rest json plugin.
Before going into details let’s start with Rest what is rest?
REST stands for Representational State Transfer. (It is sometimes spelled “ReST”.) It relies on a stateless, client-server, cacheable communications protocol — and in virtually all cases, the HTTP protocol is used.
REST is an architecture style for designing networked applications. The idea is that, rather than using complex mechanisms such as CORBA, RPC or SOAP to connect between machines, simple HTTP is used to make calls between machines.
After Installing Rest JSON plugin we got additional pallet activities.
Now let’s start with simple example that accept 2 numbers in json format and return result as sum of 2 numbers using POST Method.
Json formate of request will be:
{
“Number1”:123,
“Number2”:105
}
Now the first step is to create HTTP receiver activity in Process which will receive request via HTTP. After this I am adding Rest Dispatch and Reply activity from Rest JSON pallet.
Provide http connection to HTTP receive activity as shown in below figure.
Next step is to configure Rest Dispatcher. In the configuration tab select reply to “HTTP Receiver”.
Click on service editor tab you can see the Application main object, right click the application and Add rest services give proper service name and base url you can use global variable as well but I am not using it to make it more simple.
Now right click the RestService and add a resource. The fundamental concept in any RESTful API is the resource. A resource is an object with a type, associated data, relationships to other resources, and a set of methods that operate on it. It is similar to an object instance in an object-oriented programming language, with the important difference that only a few standard methods are defined for the resource (corresponding to the standard HTTP GET, POST, PUT and DELETE methods), while an object instance typically has many methods.
Give valid resource name and resource path in configuration
Right click the resource (addition) and create method
Give valid method ID and select method name as post. I have already created the sub process that actually process the json request you can give subprocess in Process name as shown in above figure.
Now click the bind button a window appear that contains input and output bindings map the configuration as shown in below figure.
Now open you configured the dispatcher, next part is to configure the sub process in order to get addition of 2 numbers.
In sub process I have added 2 activities parse json and render json
Parse JSON: It will convert JSON into xml
Render JSON: Convert XML to JSON
Configure the Parse json activity by giving the JSON String by providing the payload which you passed in input binding of Dispatcher configuration
Now configure the Rendor JSON activity by configuring the input editor tab as shown in below figure
In input configuration simply add the two input parameters as shown below
Configure the end activity by providing output of Rendor json activity to result
Now this completes the configuration part. Next phase is testing this I am using Advance rest client for testing
The result is
{
“Result”: “228”
}
Hello and thanks for your helpful tutorial – could you go thru how you would configure the TIBCO “Invoke REST API” activity to call your JSON server?
Hello Doug,
please see the post for your answer
http://www.techcyberspace.com/calling-rest-api-using-invoke-rest-api-activity-tibco/
Hello,
Can you explain how to create a Rest method where the input is structured and complex.
For instance an addCustomer method where the input is in the form
{ “customers” : [
{
“customerId”: “1”,
“name”: “Joe Doe”
},
{ “customerID”: “2”,
“name”: “Jane Doe”
}
],
“customersCount”:”2″
}
My doubt is how to specify this in the parameters section of the Request.
Thanks,
Francisco
Hi Francisco,
As per my understanding to your question you need xml schema to handle complex inputs for this you can use JSON tool available in TOOL of your Designer.
Save you JSON string in txt file.
Go to Tools->JSON tools->Generate xml schema from JSON
Provide JSON file it will generate the .xsd file
Now you can use Parse JSON Activity, configure outputeditor tab with the xml reference that you generated.
Pass payload json string comming from HTTP post data to input tab of parse JSON activity
Now you get output as XML schema you can use that XML any where.
I hope that the above answers your question
you can also refer this http://www.techcyberspace.com/calling-rest-api-using-invoke-rest-api-activity-tibco/