RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating...
Transcript of RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating...
![Page 1: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/1.jpg)
RHMAP MBaaS Services and RESTful APIs
Integrating with MongoDB and Amazon RDS
Hong Hua, Chad DarbySolution Architects @ GPTE2 May 2017
![Page 2: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/2.jpg)
Agenda
● Create an RHMAP MBaaS Service
● Expose RESTful API for CRUDL operations
● First version: MongoDB for persistence
● Second version: Amazon RDS for persistence
![Page 3: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/3.jpg)
RHMAP MBaaS Service
![Page 4: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/4.jpg)
RHMAP MBaaS Service
![Page 5: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/5.jpg)
RESTful API
![Page 6: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/6.jpg)
RESTful API
![Page 7: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/7.jpg)
RESTful API
![Page 8: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/8.jpg)
RHMAP and MongoDB
![Page 9: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/9.jpg)
RHMAP and MongoDB
● Every RHMAP project includes a hosted MongoDB instance
![Page 10: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/10.jpg)
Create a New User - Part 1
var $fh = require('fh-mbaas-api');
users.post('/', function(req, res) { console.log(new Date(), 'In user route POST / req.body=', req.body);
// // TODO: Do your work here //
res.json({'msg': 'POST Success'}); });
![Page 11: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/11.jpg)
Create a New User - Part 2
// Create a single entry/row var options = { "act": "create", "type": "myusers", "fields": req.body };
$fh.db(options, function (err, data) { if (err) { res.json({msg : err}); } else { res.json(data); } });
![Page 12: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/12.jpg)
Create a New User - Testing
![Page 13: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/13.jpg)
Get a List of Users - Part 1
users.get('/', function(req, res) { console.log(new Date(), 'In user route GET / req.body=', req.body);
// // TODO: Do your work here //
res.json({'msg': 'GET Success'}); });
![Page 14: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/14.jpg)
Get a List of Users - Part 2
// get a list of users var options = { "act": "list", "type": "myusers" };
$fh.db(options, function (err, data) { if (err) { res.json({msg : err}); } else { res.json(data); } });
![Page 15: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/15.jpg)
Get a List of Users - Testing
![Page 16: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/16.jpg)
RHMAP and Amazon RDS
![Page 17: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/17.jpg)
RHMAP and Amazon RDS
● Amazon Relational Data Services (RDS)
● Example of connecting to an external data service … could be ANY data service
![Page 18: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/18.jpg)
Create a New User - Set up Connection Pool
var pool = mysql.createPool({ connectionLimit : 10, host : process.env.MYSQL_HOST, database : process.env.MYSQL_DATABASE, user : process.env.MYSQL_USERNAME, password : process.env.MYSQL_PASSWORD});
![Page 19: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/19.jpg)
Create a New User - Perform SQL Insert
users.post('/', function(req, res) {
var values = [req.body.firstname, req.body.lastname]; var theSql = "insert into demo_users set firstname=?, lastname=?";
pool.query(theSql, values, function(err, results) { if (err) { var info = {"status" : "fail", "error" : err}; res.json(info); }
var info = {"status" : "ok", "data" : results}; res.json(info); });
});
![Page 20: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/20.jpg)
Get a List of Users - Perform Query
users.get('/', function(req, res) { var theSql = "select * from demo_users";
pool.query(theSql, function(err, rows) { if (err) { var result = {"status" : "fail","error" : err}; res.json(result); }
var result = {"status" : "ok", "data" : rows};
res.json(result); });
![Page 21: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/21.jpg)
Get List of Users - Test
![Page 22: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/22.jpg)
That’s all folks?
![Page 23: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/23.jpg)
THANK YOUplus.google.com/+RedHat
linkedin.com/company/red-hat
youtube.com/user/RedHatVideos
facebook.com/redhatinc
twitter.com/RedHatNews
Chad Darby
Hong Hua
We love your feedback!
![Page 24: RHMAP MBaaS Services and RESTful APIs - Red Hat...RHMAP MBaaS Services and RESTful APIs Integrating with MongoDB and Amazon RDS Hong Hua, Chad Darby Solution Architects @ GPTE 2 May](https://reader030.fdocuments.in/reader030/viewer/2022041116/5f29e8673e9c90760c02c351/html5/thumbnails/24.jpg)