In this tutorial, we will run through the process of exposing and RDBMS as an OData service. When OData is enabled for a datasource, you do not need to manually define CRUD operations. They are automatically created.
Note that the OData feature can only be used for RDBMS, Cassandra, and MonghoDB datasources.
Setting up an RDBMS
Follow the steps given below to set up a MySQL database for this tutorial.
- Download the product installer from here, and run the installer.
Let's call the installation location of your product the <EI_HOME> directory. This is located in a place specific to your OS as shown below:
OS Home directory Mac OS
- Install the MySQL server.
- Download the JDBC driver for MySQL from here and copy it to your
Create a MySQL database named
Create a table in the
CompanyAccountsdatabase as follows.
Enter the following data into the table:
Expose the RDBMS as an OData service
Follow the steps given below.
Start the WSO2 ESB profile.
- Open the ESB profile's Management Console using
https://localhost:9443/carbon, and log in using
adminas the username and the password.
Click Add New Datasource and enter details for the new datasource as follows.
Datasource ID Datasource Datasource Type RDBMS Datasource Type (Default/External) Leave Default selected. Database Engine MySQL Driver Class
User Name Enter your MySQL server's username. Example: root Password Enter your MySQL server's password.
If you have not assigned a password, keep this field empty.
Enable OData Select this check box.
Access the data service using CRUD operations
Open a command prompt execute the following CURL commands using CRUD operations:
Note that you should have privileges to perform CRUD operations on the database. If not, the OData service will not work properly.
To get the service document:
To get the metadata of the service:
To read details from the ACCOUNT table: