Students Data Service Sample¶
This sample demonstrates the capability of the Micro Integrator to perform CRUD operations via a data service using the SOAP protocol.
This sample contains a Data Service called StudentDataService
that include data sources and queries required to perform the CRUD operations.
Setup database to run the sample¶
-
Create a database and a user with the following details and grant that user access to the database.
CREATE DATABASE school_db; USE school_db; CREATE USER 'user'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON school_db.* TO 'user'@'localhost';
-
Create a table and insert some records.
CREATE TABLE `students` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(50) DEFAULT NULL, `school` varchar(50) DEFAULT NULL, `grade` varchar(50) DEFAULT NULL, PRIMARY KEY (`id`) );
INSERT INTO students (name, school, grade) VALUES ('Tim', 'Summer School', 7), ('Peter', 'Burnley High School', 10);
Deploying the sample¶
- Open the sample by clicking on the Students Data Service card.
- Give a folder location to save the sample.
- Open the
StudentDataService
data service artifact and update the RDBMS datasource in it by replacing theURL
,Username
andPassword
values with your database credentials. - Build and run the sample in your Micro Integrator.
Running the sample¶
Open a terminal and run the following commands to invoke the APIs.
- curl for create student operation
curl --location --request POST 'http://localhost:8290/services/StudentDataService' \
--header 'SOAPAction: urn:CreateStudents' \
--header 'Content-Type: text/xml' \
--data-raw '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:CreateStudents>
<dat:name>Sam</dat:name>
<dat:school>Mary College</dat:school>
<dat:grade>8</dat:grade>
</dat:CreateStudents>
</soapenv:Body>
</soapenv:Envelope>'
- curl for read student operation
curl --location --request POST 'http://localhost:8290/services/StudentDataService' \
--header 'SOAPAction: urn:ReadStudents' \
--header 'Content-Type: text/xml' \
--data-raw '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:ReadStudents/>
</soapenv:Body>
</soapenv:Envelope>'
- curl for update student operation
curl --location --request POST 'http://localhost:8290/services/StudentDataService' \
--header 'SOAPAction: urn:UpdateStudents' \
--header 'Content-Type: text/xml' \
--data-raw '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:UpdateStudents>
<dat:name>Sam</dat:name>
<dat:school>Mary College</dat:school>
<dat:grade>6</dat:grade>
<dat:id>3</dat:id>
</dat:UpdateStudents>
</soapenv:Body>
</soapenv:Envelope>'
- curl for delete student operation
curl --location --request POST 'http://localhost:8290/services/StudentDataService' \
--header 'SOAPAction: urn:DeleteStudents' \
--header 'Content-Type: text/xml' \
--data-raw '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dat="http://ws.wso2.org/dataservice">
<soapenv:Header/>
<soapenv:Body>
<dat:DeleteStudents>
<dat:id>3</dat:id>
</dat:DeleteStudents>
</soapenv:Body>
</soapenv:Envelope>'