Quick Start Guide
The purpose of this guide is to get you started on creating and invoking a data service using WSO2 Data Services Server (WSO2 DSS) as quickly as possible. See the following topics for details:
Introduction and key concepts
WSO2 Data Services Server provides a convenient web service interface for data stored in various datasources. That is, data that is stored in various data sources can be decoupled from the infrastructure where it is stored and exposed to external clients as a data service. Datasources such as relational databases, CSV files, Microsoft Excel files and google spread sheets can be easily service enabled using WSO2 DSS.
Creating a sample database with data
Let us now create a sample MySQL database and add some data. For the purpose of this demonstration, we will create a simple database with one table.
Download and install MySQL using Homebrew.
Open a terminal and execute the following command to start your MySQL database:
mysql.server startAccess the MySQL prompt by giving the user name and password. By default the user name is 'root' and the password is blank.
mysql -u root -pCreate the sample database named
employeedbusing the following command:create database employeedb;Open the
employeedbdatabase you just created using the following command:use employeedb;Create one table in the database using the following command:
create table employee(id VARCHAR(10) NOT NULL PRIMARY KEY, name VARCHAR(100), address VARCHAR(100));This command will create the following table in the database:
Insert employee data into the
employeetable as follows:The first employee:
insert into employee values('01','john','Boston');The second employee:
insert into employee values('02','Micheal','Dallas');The third employee:
insert into employee values('03','richard','Chicago');
You can see the data that you have added to the
employeetable of theemployeedbdatabase by executing the following command:SELECT * FROM employeeThe result will be as follow:
You now have a MySQL database with employee data.
Installing and setting up WSO2 DSS
Follow the steps given below to download WSO2 DSS.
Download WSO2 DSS from here.
Extract the zip file to a location in your computer. This location will be referred to as
<DSS_HOME>from hereon.Download the JDBC driver for MySQL from here and copy it to your
<DSS_HOME>/repository/components/libdirectory.
Before you start the server, the following prerequisites should be in place:
Ensure that you have JDK 7/8 installed in your computer.
You must set your
JAVA_HOMEenvironment variable to point to the directory where the Java Development Kit (JDK) is installed on the computer.
WSO2 DSS is now installed with the required settings.
Creating your first data service
We are now ready to start creating the first data service. We will be using the employeedb database that we created previously and we will expose the data through our data service. Follow the steps given below.
Open a terminal and navigate to the
<DSS_HOME>/bindirectory and execute the DSS startup script using one of the following commands:On Windows:
wso2server.batOn Linux:
sh wso2server.sh
When the product is started, the URL of the Management Console will be shown in the terminal as follows:
Copy this URL to your browser to open the Management Console.
Log in to the management console using the default administrator credentials: admin/admin.
In the left navigator, go to the Main tab and click Services -> Add -> Data Service -> Create. This will open the Create Data Service wizard.
In the Data Service Name field, enter 'MyFirstDS' as the name. Leave the default settings of all other options.
Click Next. This will take you to the page for adding datasources.
Click Add New Datasource. You can now specify the datasource details.
In the Datasource ID field, enter 'MyDS'.
In the Datasource Type field, select RDBMS from the list of values.
You will now be prompted to enter details of your RDBMS:
Edit datasources pageEnter the following details of your MySQL database in the relevant fields as shown above:
Database Engine: MySql
Driver Class: com.mysql.jdbc.Driver
User Name: root
Password: (Leave this blank)
Click Save to save the datasource.
Click Next. This will take you to a new page for adding queries to your service.
Now we will create a query to obtain all the employee details saved in the database.
Enter a name for the query in the Query ID field. We will use 'QueryAll'.
All datasources created for the data service will be listed for the Datasource field. Select MyDS from this list.
Specify the SQL statement in the SQL field. We will use a SELECT statement to query for all the employee details in the database as shown below.
Query detailsWe must now specify output mappings to determine how the information in the database should be displayed in the query output. We will be needing three columns (ID, Name and Address) to display the employee details. Therefore, we need to create three output mapping entries as explained below.
Click Add New Output Mapping and the following screen will open. You can now enter the first output mapping for employee ID as shown below.
Add output mappingClick Add to create the output mapping.
Repeat the steps using the following information to create the remaining two output mappings:
When you have created all the columns as output mappings, they will be listed as follows:
Add output mapping
Click Main Configuration to return to the main page.
Click Next. This will take you to a new page for connecting operations to each of your queries.
Enter a name for the operation in the Operation Name field. We will use 'getEmployees'.
All the queries defined for the data service will be listed for the Query ID field. Select 'QueryAll'.
Save the operation.
Click Finish to complete the data service creation. The 'MyFirstDS' data service is now listed as a deployed data service.
Deployed services page