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:
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
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