Building a REST Service

This section details how to build a REST service.

Procedure

  1. To define a REST Resource named MyBooks, select tibco.bwce.sample.rest > New > BusinessWorks REST Resource.
    The REST Service Wizard window opens.
  2. Specify the following values in the REST Service Wizard window.
    1. Resource Name: MyBooks
    2. Summary: Summary about the new REST service. (default)
    3. Resource Service Path: Auto-filled
    4. Resource Definition: Select Browse > Schemas > Books.xsd > Books in the Select Schema Element Declaration window.
    5. Operations: Select POST and GET check boxes.
    6. Implementation Data: Accept the default value of Structured.
  3. Click Finish.
    This creates a new process MyBooks.bwp process is opened in the Process Editor.

  4. Open the tibco.bwce.sample.binding.rest.bookstore.db package in the Project Explorer and select the BooksDB.bwp process. Drag it to the Process Editor and drop it on the implemented POST operation.
    A menu is displayed with two options: Create Invoke Activity and Create Reference and Wire Process.
  5. Select Create References and Wire Process.
    The references are added to the process. The purple chevron indicates the service and its operations that can be referenced by the process.
  6. To update the POST process to invoke the appropriate external service operation:
    1. Click the addBooks operation.
    2. Select and drag the operation to the left of the postOut activity and drop it. An Invoke process activity is created.

  7. Click the newly added activity. Select the icon and connect addBooks to postOut.

  8. Click the getAllBooks operation and select, drag, and drop the operation to the left of the getOut activity in the OUT process.
  9. Connect getAllBooks to getOut.

  10. Save your changes.
  11. Click the addBooks activity and select Properties > Input.
  12. Expand the data tree in the Data Source pane to locate the Book element.
  13. Drag the Book element from the left to the Book* element on the right.
  14. In the pop-up window, select Make a Copy of each " Book" and click Finish.

    The Input tab will look like this:

  15. Save your changes.
  16. Click the postOut activity and open the Properties > Input tab. Expand the post activity and drag the Book* element from left to right.
  17. In the pop-up window, select the For each option and click Next. Click Finish on the Auto-Map window. The Properties > Input tab will look similar to this:


  18. Click getAllBooks and select Properties > Input.
  19. In the XPath Expression pane, add a dummy value to the input element, such as, "Get All Books". The input must be in quotes.
  20. Click the getOut activity in the Process Editor, and select the Properties > Input tab. Expand the getAllBooks activity and choose Book* to map the Book* element from left to right. In the pop-up window, choose Make a Copy of each " Book" and click Finish. The tab will look similar to this:


Result

Your project is complete without any errors.