Using Basic REST Binding

In this REST Bookstore sample you can use the RESTful service to add, and retrieve books from a Bookstore (in this sample, Bookstore is files as a datastore). This sample uses two REST methods: POST and GET.

Prerequisites

Install the latest Google Chrome version in the standard default location.

Note: If you are accessing the sample from the Welcome page of TIBCO Business Studio™ for BusinessWorks™, go directly to Step 3.

Procedure

  1. In the samples directory, select binding > rest > Basic and double-click tibco.bw.sample.binding.rest.Basic. For more information, see the Accessing Samples section.
  2. In theProject Explorer, expand the tibco.bw.sample.binding.rest.Basic project.
  3. Set the default application profile to match the OS you are running on. For more information, see Setting the Default Application Profile.
  4. Fully expand the Processes directory and double-click books.bwp.
  5. Click Run > Debug Configurations.
  6. At the left hand tree of the Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
  7. Click the Applications tab, and then click the Deselect All button, if you have multiple applications. Select the check box next to tibco.bw.sample.binding.rest.Basic.application.
  8. Click Debug. This executes the sample in Debug mode.
    The console window shows engine messages similar to: Started BW Application [tibco.bw.sample.binding.rest.Basic.application:1.0].
    The OSGI command to list REST and Swagger URLs is lrestdoc, which lists the following discovery URL:
    [Application Name]: tibco.bw.sample.binding.rest.Basic.application [Discovery Url]: http://localhost:7777/tibco.bw.sample.binding.rest.Basic.application.
  9. Launch Google Chrome browser and open http://localhost:7777/tibco.bw.sample.binding.rest.Basic.application.

Result

The Swagger API Page displays:

Click POST and provide the JSON payload.

You can use the books.json payload provided with the sample present at BW_HOME\samples\binding\rest\Basic\books.json. On successful POST of Data, the books.log file is created in the c:/tmp/RestBasic folder (or /tmp/RestBasic on Unix Platform), with the data you just posted.

Click Get > Try it out to view all the books that you have just posted. You can see the data similar as the following:



You can also change the output file location.

To change the output file location, go to tibco.bw.sample.binding.rest.Basic.application > Package Unit, and open Properties file for editing. Depending on your Operating System under test, edit the output file location in either the UnixProfile column or WindowsProfile column.

The Books_Invoke.log file is generated at c:\tmp\RestBasic\. This file contains POST Books and GET Books output from the Client process.

Understanding the Configuration

The project contains the following processes.

  • Books Process: In this process, a REST service is created that performs two operations, POST and GET. The POST operation posts one or more books to the bookstore or books collection (in this case a file) and the GET operation retrieves all the books from the Bookstore (file). In the Books/post operation, a sub process is called to add books to the file. The PostBooksToFile operation is implemented in the BooksFile subprocess. In the Books/get operation, a sub process is called to retrieve books from the file. The GetBooksFromFile operation is implemented in the BooksFile subprocess. The following diagram depicts the Books process.

  • BooksFile Subprocess: File handling is managed using the BooksFile sub process, which adds and retrieves books from the file. The BooksFileService service implements the operations to add and get books from the file. In BooksFileService/PostBooksToFile, Render JSON activity is used to render data that the user has posted, write it to a file, read the file, parse the data, and then post the data back to the user. In BooksFileService/GetBooksFromFile, the file previously created is read, parsed, and then the data is returned to the user.



  • Client Process: This is a REST Client process which uses Invoke REST API activity to retrieve data from the REST Server. This process is used to Invoke the POST and GET operations on the REST resource.

    For example, in POST_Books, we provide HTTP Client Resource that listens to the same host and port as that of the server. The Resource Path is "/books", HTTP Method is "POST", and Request and Response type is JSON. In the Message Body, we provide the JSON payload which is read from the file present at BW_HOME\samples\binding\rest\BookStore\samplejson\books.json .

    This JSON payload is then posted to the output file.



Troubleshooting

  • If you do not see the REST Swagger API page, verify whether the application has started.
  • If you see any problem markers in the project, clean the project by invoking Project > Clean or try switching to a clean new workspace.
  • If you get any File was not found exception, verify whether the books.json file is present at the location as described in the Input_File Module Property.