Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Building Mobile Apps with Apache UserGrid, the Open Source Baas

3,479 views

Published on

All Things Open 2014 - Day 1
Wednesday, October 22nd, 2014

David Johnson
Software Developer for Apigee & Apache Software Foundation
Mobile
Building Mobile Apps with Apache UserGrid, the Open Source Baas

Published in: Technology

Building Mobile Apps with Apache UserGrid, the Open Source Baas

  1. 1. Dave Johnson Apigee Building Mobile Apps with Apache Usergrid, the Open Source BaaS
  2. 2. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 2 Agenda » Overview: why Usergrid » Exploring the Usergrid API » Creating an app with Usergrid » v1 - Add Logins & Signup » v2 - Add Checkins » v3 - Add Follower relationships » v4 - Package & run via Apache Cordova » Running & Deploying Usergrid » Q & A
  3. 3. Usergrid Overview
  4. 4. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 4 Why Usergrid? » Don’t build a server PHP Ruby Java NodeMySQL PaaS Services in the “cloud” App Server Cloud
  5. 5. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 5 Why Usergrid? » Focus on building your app Services in the “cloud” App Cloud
  6. 6. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 6 What is Usergrid? ! » Mobile Backend as a Service (mBaaS) ! » Backend as a Service (BaaS) ! » Database as a Service (DBaaS) ! » REST API wrapped around Cassandra DB
  7. 7. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 7 What is Usergrid? » A Web Application ! » A Management Portal ! » Client SDKs » iOS, Android, JavaScript, Node, Ruby, Java, Perl, .Net, Command-line, …
  8. 8. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 8 What is Usergrid? » Core services you need to build apps: » JSON object indexing & query » Geo-location & geo-queries » Connections & Collections » Users, Groups, Social Graph » Authentication, Roles & Permissions » Asset & File Management ! » Soon: Push Notifications
  9. 9. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 9 What is Usergrid?
  10. 10. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 10 An Apache Incubator Project
  11. 11. Exploring the Usergrid API
  12. 12. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 12 Usergrid REST API » JSON over HTTP » POST, GET, PUT and DELETE JSON Entities ! » Entities have UUID, Name, Type » Entities have name/value properties ! » All Entity properties are indexed » SQL-like syntax for Entity queries
  13. 13. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 13 Usergrid REST API »Each application has root URL like this »http:// host/${org}/${app} ! » Entities exist in Collections »http:// host/${org}/${app}/${collection} ! » And you can define Collections of custom Entities with any properties you want
  14. 14. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 14 Usergrid REST API » There are special built-in Entity Collections: » http:// host/${org}/${app}/users » http:// host/${org}/${app}/groups » http:// host/${org}/${app}/roles » http:// host/${org}/${app}/activities » http:// host/${org}/${app}/assets
  15. 15. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 15 Connections » Entities can have Connections to other Entities ! » For example, to get all Entities that Dave is connected to via a connection of type “pets” ! » http:// host/${org}/${app}/users/dave/pets
  16. 16. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 16 Collecting Cats » Demo the Portal ! » Create Application » Create User Dave with Default Role » Create Cats Collection » Setup “Dave has Cats” Connections
  17. 17. Creating an app with Usergrid
  18. 18. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 18 Let’s create a checkin app » A simple checkin app to demonstrate Usergrid features: ! » Login & signup » Roles & Permissions » Following, Followers and Checkins » Usergrid JavaScript SDK ! » Built with jQueryMobile & Cordova
  19. 19. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 19 Define the data model » Usergrid provides the basic REST API ! » You must decide: » Entity Types & Properties » Entity Connections » Users Roles & Permissions
  20. 20. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 20 Entities & Connections » Entity Collections » Users » Checkins ! » Entity Connections » Users Follow Users » Users Have Checkins
  21. 21. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 21 User Role: Guest » User who has not signed up yet » Permissions User with Guest Role: ! ! ! ! » Guest user POSTs to register » Usergrid takes care of account activation GET POST PUT DELETE /users/* 🚫 ✅ 🚫 🚫
  22. 22. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 22 User Role: Default » Permissions for User with Default Role: GET POST PUT DELETE /users/${user}/** ✅ ✅ ✅ ✅ /activities/* ✅ 🚫 🚫 🚫 /users/* ✅ 🚫 🚫 🚫 /users/${user} ✅ 🚫 ✅ 🚫
  23. 23. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 23 App setup in the Portal » Quick demo ! » Take a look at Roles & Permissions » Ensure they are setup right
  24. 24. Adding Login & Signup
  25. 25. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 25 Getting started » Pre-requisites: ! » Usergrid JavaScript SDK ! » jQuery Mobile ! » Apache Cordova ! » Your favorite dev environment
  26. 26. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 26 Get setup in an IDE
  27. 27. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 27 JavaScript SDK - login var client = new Usergrid.Client({ appName: 'checkin1', orgName: 'test-organization', URI: 'http://10.1.1.161:8080' }); ! client.login(username, password, function(err, res, entity) { if (err) { // inform user of error } else { // change to View Checkins page } });
  28. 28. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 28 jQueryMobile
  29. 29. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 29 JQuery Mobile page structure <div data-role="page" id=“my-page-id“ data-theme=“a”> ! <div data-role="header" data-theme="a"> // header goes here </div> <div data-role="content"> // page goes here </div> <div data-role="footer" data-theme="a"> // footer goes here </div> </div>
  30. 30. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 30 Apache Cordova
  31. 31. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 31 Apache Cordova » Hybrid approach to mobile apps: » Write code in with HTML5 & JavaScript » Package as a truly native app » Access device features: camera, contacts, etc. ! » iOS and Android, but also Amazon Fire, Blackberry, Windows Phone and more ! » Tool support: Adobe, Eclipse, Netbeans, IntelliJ, etc.
  32. 32. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 32 Get setup in an IDE » Demo time ! ! ! ! ! ! » Create Cordova project in IDE » Add Login & Registration Page
  33. 33. Adding Checkins
  34. 34. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 34 Checkins as Activities » Usergrid supports notion of Activity » And supports a “Following” Connection ! » Users post Activities to their own Collection » POST /users/${user}/activities! ! » Users can see Activities those they follow » GET /activities
  35. 35. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 35 JavaScript SDK - create checkin var data = { type: “checkin", content: content, verb: “post", actor: { username: user.get(“username") } }; client.createUserActivity(user.get("username"), data, function( err, response, activity ) { if (err) { // alert user of error } else { // send user back to View Checkins page } });
  36. 36. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 36 What we’ll add » View Checkins Page ! » Add a Create Checkin Page ! » View Single Checkin Page
  37. 37. Add Follower relationships
  38. 38. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 38 Usergrid Social Graph » Usergrid provides Social Graph features including Following and Groups ! » Fred can follow Barney: » POST /users/fred/following/barney! ! » Fred can see his followers: » GET /users/fred/followers
  39. 39. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 39 JavaScript SDK - follow user var target = // user to be followed var options = { method: 'POST', endpoint: ‘/users/' + me + '/following/users/' + target }; ! client.request(options, function (err, data) { if (err) { alert("Unable to follow user " + target); } else { alert("Followed user " + target); } });
  40. 40. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 40 What we’ll add » View Users Page ! » View User Page with Follow Button
  41. 41. Package & run your app
  42. 42. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 42 Apache Cordova » Demo time ! » Use Cordova to launch the app in iOS
  43. 43. Running & Deploying Usergrid
  44. 44. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 44 Developing with Usergrid » Three ways to run Usergrid locally: » All-in-one Usergrid Launcher » Install Tomcat, Cassandra and Usergrid » Start Usergrid instance via Vagrant ! » Or find a BaaS provider that runs Usergrid: » e.g. Apigee’s API BaaS is free to use
  45. 45. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 45 Usergrid deployment options » Do it yourself with Tomcat, Cassandra and Puppet, Chef, etc. ! » Do it yourself on AWS via Usergrid AWSCluster » AWS Cloud Formation Template » Plus supporting Bash and Groovy scripts ! » Let somebody else run it for you… » Hint hint 😃
  46. 46. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 46 Deployment Architecture UG1 Mobile Cassandra Cluster Load Balancer Web Tomcats (shared nothing)
  47. 47. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 47 Deployment Architecture UG2 Mobile Cassandra Cluster Load Balancer ElasticSearch Cluster Web Tomcats (shared nothing) Distributed Queue
  48. 48. Wrapping up…
  49. 49. © 2013 Apigee Confidential – All Rights ReservedThis work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.© Copyright Apigee 49 Questions? » Apache Usergrid » http://usergrid.incubator.apache.org ! » Apigee API BaaS » http://goo.gl/zcjRxC ! » Dave Johnson » https://github.com/snoopdave/ » usergrid-mobile » usergrid-vagrant » http://twitter.com/snoopdave » http://rollerweblogger.org/roller
  50. 50. Thank you

×