REST Reference Tutorial

The REST reference tutorial shows you how to create a simple REST Invoke to an existing REST Service defined by a Swagger specification.

You cannot convert REST reference to SOAP or vice versa.

Prerequisites

The REST service which you want to invoke must be accessible from the reference process at the time of its invocation.

Creating a New Application

  1. Open TIBCO Business Studio.
  2. Open the Design perspective by clicking the Design icon in the upper right corner.
  3. Click File > New > Other > BusinessWorks > BusinessWorks Application Module and click Next.
  4. Enter tibco_bw_sample_binding_rest in the Project Name text box. Do not change the remaining default settings.
  5. Click Finish. This will create a new application module with an empty process.

Obtaining the REST Service Swagger File

Note: The REST service for which you want to obtain the Swagger file must be running.
To obtain a Swagger file for a REST service, do the following:
  1. On the Apps page of the TIBCO Cloud Integration, click the service whose Swagger file you want to consume to create a REST reference.
  2. Click the Download link icon next to the API name. It downloads the JSON file for the service to your local machine.
  3. Open the location of the downloaded file in File Explorer view.
  4. Import the downloaded JSON file by dragging it from the File Explorer view and dropping it into the Service Descriptors folder of your project.

An alternate way to import the Swagger file is from the Cloud Applications view in TIBCO Business Studio. Expand the application under Apps, and drag the endpoint into the Service Descriptors folder of your project. The Swagger file imported from the Cloud Applications view is a concrete WSDL/JSON file.

Importing the JSON File into your Project

  1. In the Project Explorer, expand tibco_bw_sample_binding_rest application module.
  2. Right-click Service Descriptors and select Import > Import... > General > File System and click Next.
  3. In the File system dialog, click the Browse button and browse to the location of the Books.json file.
  4. Select the check box next to Books.json in the left pane and click Finish..

Creating the REST Reference

  1. In the Project Explorer, completely expand the tibco_bw_sample_binding_rest folder under Service Descriptors.
  2. Select the /books under Books.json and drag and drop it to the right side of the process in the Process Editor. The references are added to the process. The purple chevron indicates the service and its operations.
  3. In the Process Editor, right-click Add Activity > General Activities > Timer. Optionally, you can configure the Sleep activity with IntervalInMillisec as 3000 in a similar manner and connect the Timer with Sleep.
  4. Drag the get operation under the purple chevron and drop it on the right of Timer activity (or Sleep if configured) and connect the Timer activity with the get activity.
  5. Drag the post operation under the purple chevron and drop it on the right of the get activity, connect the get activity with the post activity.
  6. Right-click the get activity select Show Properties View.
  7. In the Properties view, select the Input tab and click Show Check and Repair icon in the icon bar on the upper right corner of the Properties view.
  8. Select the check box under Fix and click OK.
  9. Click Show Check and Repair icon again.
  10. Select the check box under Fix and click OK.
  11. Select the post activity and right click and select Show Properties View. In the Properties View, select the Input tab and select Data Source tab.
  12. Expand $getin the Data Source tab completely.
  13. In the XPath Expression pane, expand the post-input completely.
  14. Drag and drop Book* from the Data Source tab to the Book* under post-input in the XPath Expression pane.
  15. In the Drop dialog, select Make a copy of each "book" radio button and click Finish.
  16. Click Show Check and Repair icon in the icon bar on the upper right corner of the Properties view.
  17. Select the check box under Fix and click OK.
  18. Click Show Check and Repair icon again. Select the check box under Fix and click OK.
  19. In the Project Explorer, select Books.json under Service Descriptors of tibco_bw_sample_binding_rest_basic application module, and right click Open With > Text Editor and locate the "host" attribute. Make a note of the host name and port number.

  20. Expand the Resources folder under the tibco_bw_sample_binding_rest_basic application module.
  21. Double-click HttpClientResource.httpClientResource.
  22. In the HTTP Client section, change the Default Host to BW.HOST.NAME and Default Port to 443 and select the Default Confidentiality check box. This is required when accessing services running in the cloud.

  23. Click File > Save All.

Testing the REST Reference

You can now test the REST service using the built-in tester and the Swagger UI. To do so follow these steps:
  1. Click Run > Debug Configuration.
  2. In the left pane of the Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
  3. Click the Applications tab, then click Deselect All if you have multiple applications.
  4. Select the check boxes next to tibco_bw_sample_binding_rest_basic_application and tibco_bw_sample_binding_restapp.
  5. Click Debug.. This runs the sample in debug mode. The Console view is opened and shows engine messages similar to: Started BW Application [ tibco_bw_sample_binding_rest_basic_application:1.0]
  6. In the Debug view, expand BWApplication [BusinessWorks Application] > <launched> BWEclipseAppNode > tibco_bw_sample_binding_rest_Process and select get.
  7. In the JobData view, you can see the job data of the get activity.