29 Jun How to implement rest services using BW 5
What is REST?
REST (Representational State Transfer) is an architectural style for designing Public APIs and networked applications in the form of Web Services. REST is a lightweight and non-standardized approach towards development of Web Services as it doesn’t comply to any hard and fast standards unlike SOAP.
REST based Web Services are called RESTful web services and such services use HTTP Protocol for data transport. XML, JSON etc. are used as data formats for input and output of RESTFul web service operations.
REST vs SOAP
REST, unlike SOAP is not a protocol.
REST is an architectural style and a design for network-based software architectures.
REST concepts are referred to as resources. A representation of a resource must be stateless. It is represented via some media type. Some examples of media types include XML, JSON, and RDF. Resources are manipulated by components. Components request and manipulate resources via a standard uniform interface. In the case of HTTP, this interface consists of standard HTTP ops e.g. GET, PUT, POST, and DELETE.
Scenario to Create a RESTFUL Web Services in Tibco BW:-
Lets take simple scenario to create Restful web services in Tibco bw. This service will be used to query Employee Details from a database table based on EMP ID.
For Testing Purpose, the client process will be sending a hard coded EMPID for which, our service will fetch the Employee details from the database and will send back as a service response in XML String format.
Let’s now go step by step to develop our Restful Web Service:
Creating Shared Connection Resources for HTTP and JDBC:
XML Schema to be used as Restful Service Input and Output
Let’s Create Implementation process for our RESTFUL Web Services in Tibco BW.
Our business logic in this example case is very simple. We are just going to use the schema that we created in above step as Input and Output in our process and will use JDBC Query Activity to query account details from the database so that account details are sent as output from the process.
In the JDBC Query Activity configuration tab, we are going to write following query to fetch the Employee details from the database:
Create RESTful Service Using REST Dispatch and Reply activity
Let’s create service by using REST Dispatch and Reply activity from the REST & JSON Palette. Using REST Dispatch and Reply activity, we can expose a BW process as a RESTFul service. The BW Implementation process that we created will be used in this case as RESTful service implementation process.
The Starter activity for the process with REST Dispatch and Reply is HTTP Receiver and we will use the connection created in earlier steps.
In the Service Editor tab, click on the application.
Right Click on the Application and choose Add–>RestService
A new REST Service will be added under the application. I have renamed it to EmployeDetailsService.
For this EmployeDetailsService, specify the base URL. This URL should be same which you configured in your HTTP Connection:
Now Right Click on your service in the Service Editor tab and choose Add–>Resource
New Resource will be added under the service. I have renamed this resource to EmployeeResource. We don’t need to add any parameters as we will add parameters at method level instead.
The Resource will look like below:
After adding the request and response elements under the Method.
Select the business process at the Method Level to associate the Business Process with the Method. This is similar to our Operation and Implementation process in Service Activity.
Now click on the method name so that Bind button in the bottom appears. Using Bind button, we will map the Input and Output for our service for this method.
As you can see in below diagram that we have used Bind button and then mapped EmpID as Input. Using Render-XML function, the response is mapped as output string:
With this step we complete our configuration work for REST Dispatch and Reply activity.
Under the input Editor of Invoke REST API we have an existing complex element named as Query which a child element as PARAM. Lets rename PARAM as EMPID which is the request parameter in our scenario as show below
For testing purpose lets hard code the EMPID as 1 as shown below
Load the Client and the RESTFUL Service in our TIBCO BW Tester and create a job on Client process to invoke the RESTFUL service via HTTP Receiver.