Ionic + Parse JS API or Parse REST API


#1

I try to build mobile app and i choose Parse as my Backend service.
But which one i should choose ? using Parse Javascript API or REST API ?

And there is description that say…
" There are a few things that are not ideal about the existing Parse JavaScript API in AngularJS. The existing API is modeled after Backbone Models and the main problem is setters are used instead of object properties. instance.set(‘property’, ‘value’) doesn’t really fit well with things like ng-model. "

Any help and suggestions ???
Thks in advance.


#2

You should use the REST API.
And here is a tutorial of a REST API integration in Ionic.


#3

Thks @benjamin_bnds

from the tutorial it use $http and ngResource to communicate to backend.

Another tutorial suggest…
"Wrap Parse asynchronous calls inside AngularJS $q promises, instead of just performing Parse queries directly in your models or controllers. One of the benefits is that your data changes will be digested by AngularJS automatically. "

Any experience with Parse or any suggestion???
Thks in advance.


#4

Maybe this tutorial can help you.


#5

Thks…Good Tutorial…

but the example using javascript api and using controller without factory service.
Is there any example using ionic+parse and wrap it with angularjs factory service such as parseUserService and facebookService…

Thks.


#6

i am using Parse in this project https://github.com/aaronksaunders/dcww

here is the specific service for integrating with Parse - https://github.com/aaronksaunders/dcww/blob/master/www/js/services.js


#7

Thks @aaronksaunders for the great example.

So ur using Javascript API.
Any comment regarding to above statement about…
" There are a few things that are not ideal about the existing Parse JavaScript API in AngularJS. The existing API is modeled after Backbone Models and the main problem is setters are used instead of object properties. instance.set(‘property’, ‘value’) doesn’t really fit well with things like ng-model. "

Also is it better to use $q than $resource ???
I am still beginner and need extra to learn and understanding.

Thks in advance.


#8

Hi

You can use the Object.defineProperty to add in your getters and setters so you can then easily access your models properties.

see the following

.factory('RoutedataService', function($q, LogService) {

  var ParseObject = Parse.Object.extend("Routedata"),
      Routedata = {};

  // Properties
  Object.defineProperty(ParseObject.prototype, "routeNumber", {
    get: function() {
      return this.get("routeNumber");
    },
    set: function(aValue) {
      this.set("routeNumber", aValue);
    }
  });
  Object.defineProperty(ParseObject.prototype, "routePoint", {
    get: function() {
      return this.get("routePoint");
    },
    set: function(aValue) {
      this.set("routePoint", aValue);
    }
  });   
  return {

    RoutedataObject: ParseObject,

    Routedata: Routedata,

    getRoutedata: function(){
      LogService.add('getRoutedata Start');
      //Creating a deferred object
      var deferred = $q.defer();
      //Query Parse
      var query = new Parse.Query(ParseObject);
      query.ascending('createdAt');
      query.find({
        success : function(data) {
          LogService.add('getRoutedata Success');
          //Passing data to deferred's resolve function on successful completion
          deferred.resolve(data);
        },
        error : function(err) {
          //Return error message incase of failure
          LogService.add('getRoutedata Failed: ' + err);
          deferred.reject(err);
         } 
      });
      //Returning the promise object
      return deferred.promise;
    }
  }
})

then in your controller do something like

function LoadRouteData() {

    RoutedataService.getRoutedata()  // Get Route Data for all route numbers
        .then(function (data) {
            RoutedataService.Routedata = data;
            if (RoutedataService.Routedata.length > 0) {
                showRoutes(GeoService.Geomap, data);
            }
        },
        function (err) {
           // HandleError(err);
        });
}

you can then access the routedata points like RouteData[i].routePoint etc…

hope this helps


#9

i would recommend using $resource, but if you are using the Parse API, it is a non-issue since all of the parse API calls return a promise.

As for the BackboneModel issue, you can always wrap all of the parse models so they can be used more effectively in angularJS


#10

Ok tq @aaronksaunders . I will learn more about $q.

Could u give me example/ explanation about “wrap all of the parse models so they can be used more effectively in angularJS”.???

In my case using ionic+parse and I want to do a social login. What is the best practise?? Using ngcordova oauth or facebook connect plugin or Other ???

Thks in advance…


#11

Thks @darrenahunter,

Do u have any sample project using ionic + parse that u can share to me like at github???
From above sample about Object.defineProperty still hard for me to understand and still need to learn more.
What the pros using that kind Object property?? because there is little example using it.

Thks.


#12

Have a look at https://github.com/brandid/parse-angular-patch


#13

yep spot on campers - sorry for late reply was away


#14

thks @campers.

any sample apps using angular parse patch ??
already saw readme but still dont know how to apply the patch to our application.
still need to build factory service or no need factory service just controller is enough???

Thks in advance.


#15

+1 for REST-API . Angular works well with REST-API and it will be easy to switch to other things in future.


#16

Using REST API seems to give your app more flexibility for future changes (changing backends to Mbaas like Azure Mobile for instance; it has a REST API as well). It makes you less “boxed in”. If that is a non issue you could use the js version as well, but i’d recommend the brandid wrapper to save you some time.

If you want a nice REST API tutorial, read this one: http://www.htmlxprs.com/post/12/tutorial-on-using-parse-rest-api-and-ionic-framework-together

cheers