Implementing a REST Service Using a JSON File with "allOf" Keyword
This REST sample shows how to use the OpenAPISpecification 3.0 JSON file with "allOf" keyword to create a RESTful service for adding, updating, and retrieving pets data from a pet store.
The sample uses the following HTTP methods for the Pets REST resource:
-
GET: Get details of dog from the petstore
-
PATCH: Update dog data to the petstore
-
POST: Add cat details to the petstore
Implementing a REST Service Using a JSON File with "allOf" Keyword:
- Procedure
-
In the samples directory, select binding > rest > allOf and double-click tibco.bw.sample.binding.rest.allOf. For more information, see the Accessing Samples section.
-
In the Project Explorer, expand the tibco.bw.sample.binding.rest.allOf project.
-
Set the default application profile to match the operating system you are using. For more information, see Setting the Default Application Profile.
-
Fully expand the Processes directory and double-click Pets_Service.bwp.
-
Click Run > Debug Configurations.
-
At the left side pane of the Debug Configuration wizard, expand BusinessWorks Application and select BWApplication.
-
Click the Applications tab and then click the Deselect All button, if you have multiple applications. Select the checkbox next to tibco.bw.sample.binding.rest.allOf.application.
-
Click Debug. This runs the sample in the debug mode.
The console window shows engine messages similar to:
Started BW Application [tibco.bw.sample.binding.rest.allOf.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.allOf.application1.0
[Discovery Url]: http://bwin2k16-67:7777/tibco.bw.sample.binding.rest.allOf.application
-
Launch the Google Chrome browser and open
http://bwin2k16-67:7777/tibco.bw.sample.binding.rest.allOf.application
.The Swagger API Page displays as follows:
-
Click any of the operations, such as GET, PATCH or POST, displayed on the web page.
-
After completing the operations on the page, in TIBCO Business Studio for BusinessWorks, click the Terminate icon (
) to stop the application.
PetDogs
-
GET dog details
-
PATCH dog details
PetCats
-
POST cat details
GET dogs returns an output similar to the following :
{"id":10,"name":"Oreo","status":"Available","bark":false,"breed":"Husky"}
POST cats returns an output similar to the following:
{"id":110,"name":"Kitty","status":"Sold","hunts":true,"age":"12"}
The PetData.log file generated with the following information:
***********Output of Pets Data***********GET Dog having allOf Pet--> {"id":10,"name":"Oreo","status":"Available","bark":false,"breed":"Husky"}**************************************************************
PATCH Dog having allOf Pet--> {"id":20,"name":"Jasper","status":"Sold","bark":true,"breed":"Shepherd"}**************************************************************
POST Cat having allOf Pet--> {"id":110,"name":"Kitty","status":"Sold","hunts":true,"age":12}**************************************************************
Understanding the Configuration
The project contains two processes, Pets_Service.bwp and Client.bwp.
Pets_Service Process: In this process, the Pets REST service performs the post, get, and patch operations. It updates details of a dog to the petstore and retrieves the dog details from the petstore. The cat details are added using the post operation. This service is created using the Petstore_allOf.json file. The file has Dog, Cat, and Pet objects. The Dog and Cat objects use the "allOf" keyword to combine the main 'Pet' schema with 'Dog-specific' and 'Cat-specific' properties respectively.
Client Process: This is a REST Client process, which uses the REST Invoke activity to retrieve data from the REST Server.
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 clicking Project > Clean or try switching to a clean new workspace.