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.
Procedure
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
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
The , 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. 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 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.