Mobile applications usually refers to external data source in order to read, create, update and delete information. A back-end application is the background layer providing a data structure and a set of REST services that allow the mobile application (front-end layer) to access to this data. In this lesson you learn how to create a simple back-end application with WebRatio Mobile Platform.
How to create a DataService Project
The back-end is modeled in a dedicated project called DataService Project. Let’s create a new DataService Project. In WebRatio Mobile Platform click on "File", select the "New" option and then "DataService Project". In the opening dialog enter a name for the project with no space in it, such as "CRMback-end", then press the "Finish" button to confirm.
How to publish Data Services
Now that we have our DataService Project, let’s start publishing a data service.
Let's start adding a database in the Domain Model. Right-click on the Domain Model node, select the "Add" option and then the "Database" option. Write a name for the database, such as "CRM". Let's choose the database type. Copy the Sample URL string connection and paste it next to the "URL" property. Replace the "host" placeholder with the IP address of the workstation hosting the database (e.g., "localhost"), then replace the "port" placeholder with the port number on which the database engine is running (e.g., "55432") and finally replace the "database" placeholder with the name of the database to which you want to connect (e.g., "CRM"). Enter a valid username and password for connecting the database.
Once we properly defined a database, let's check the database connection. Right-click on the database node from the Outline View and choose the "Refresh" option.
Once the database is properly connected, let's set the "Schema" property. Select the database node and choose the "APP" option for the "Default Schema" property. Let's add now the "Employee" class in the Domain Model. Select the "Class" item from the toolbar and place it in the "Domain Model" area. Type a name for the class such as "Employee".
Let's add now the properties we think that characterize an employee (e.g., First Name, Birth Date, Role, ...). Right-click on the "Employee" class and select the "Edit Class ..." option. In the opening dialog press the "Add" button and type a meaningful name for the attribute. Repeat the same operation in order to add the all the other attributes and press the "OK" button.
Now let’s start configuring the methods exposed as data service for the "Employee" class. Press the "Select" button next to the "Data Services Database" property. Select the "CRM" database, then press the "OK" button. Then choose "APP" for the "Data Service Schema" property.
Press the "Configure Services" button next to the "Services Configuration" property. In the opening dialog you can define for each defined Role in the project, the operations exposed as data service for the selected class of the Domain Model. The "Role" field indicates the role for which you want to specify the permission.
By default it’s set to "Authenticated User". Select the checkbox corresponding to the "Read", "Create", "Update", and "Delete" method. This means that the data contained in the "Employee" class will be available for all this operations from the front-end layer. Then press the "OK" button.
In order to work properly, the back-end layer needs to keep a set of information about the history of changes occurred to the "Employee" objects. WebRatio Mobile Platform automatically adds two new attributes intended to record the operations occurred on the class instances.
Let's use the Synchronization process to export the "Employee" class in the database. Right-click on the "CRM" database node and choose the "Synchronize" option. Press the "Export All Object" button then press the "Next" button. Finally press the "Finish" button to complete the process.
How to see the published services
Now let’s save the DataService Project, then press the "Generate and Run" button in the main toolbar.
Once the generation process is completed, a new browser window will be automatically opened and the Swagger Page will be displayed in it. This page contains the full description of all the Web Services published by the DataService Project.
Let’s have a look to the generated WADL file for our Web Services. In a new browser tab window enter the URL "http://localhost:8080/CRMback-end/wadl.do" and press enter. The WADL file displayed in the page is the exact description for the REST web services we defined in our DataService Project.