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.

Rest JSON TIBCO

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.

Rest JSON TIBCO

Next step is to configure Rest Dispatcher. In the configuration tab select reply to “HTTP Receiver”.

Rest JSON TIBCO

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.

Rest JSON TIBCO

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

Rest JSON TIBCO

Right click the resource (addition) and create method

Rest JSON TIBCO

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.

Rest JSON TIBCO

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

Rest JSON TIBCO

Configure the Parse json activity by giving the JSON String by providing the payload which you passed in input binding of Dispatcher configuration

Rest JSON TIBCO

Rest JSON TIBCO

Now configure the Rendor JSON activity by configuring the input editor tab as shown in below figureRest JSON TIBCO

 

In input configuration simply add the two input parameters as shown belowRest JSON TIBCO

 

Configure the end activity by providing output of Rendor json activity to result

RestJson Tibco

Now this completes the configuration part. Next phase is testing this I am using Advance rest client for testing

Rest JSON TIBCO

 

The result is

{

“Result”: “228”

}

Rest JSON TIBCO