REST Data Service Sample¶ This sample demonstrates the capability of the WSO2 Integrator: MI to perform CRUD operations via a data service using the REST protocol. This sample contains a Data Service called RESTDataService 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 REST Data Service card. Give a folder location to save the sample. Open the RESTDataService data service artifact and update the RDBMS datasource in it by replacing the URL, Username and Password values with your database credentials. Build and run the sample in your WSO2 Integrator: MI. Running the sample¶ Open a terminal and run the following commands to invoke the APIs. curl for create student curl --location --request POST 'http://localhost:8290/services/RESTDataService/student' --header 'Content-Type: application/json' \ --data-raw '{ "_poststudent": { "name" : "Will Smith", "school": "Beverly Hills School", "grade": 10 } }' curl for read student curl --location --request GET 'http://localhost:8290/services/RESTDataService/student' curl for update student curl --location --request PUT 'http://localhost:8290/services/RESTDataService/student' --header 'Content-Type: application/json' \ --data-raw '{ "_putstudent": { "id" : 3, "name" : "Will Smith", "school": "Beverly Hills School", "grade": 11 } }' curl for delete student curl --location --request DELETE 'http://localhost:8290/services/RESTDataService/student' --header 'Content-Type: application/json' \ --data-raw '{ "_deletestudent": { "id" : 3 } }'