. . .

Android Code Comparison between Parse and ApiOmat

If you haven't migrated from Parse yet, check out this tutorial to learn how easy it is.

Facebook announced on January 28th 2016 that it would be shutting down its Parse service in January 2017. Parse is now an open source solution, so if you want to host it yourself you can, but Parse's feature sets have aged and you will be reliant on the open source contributers to ensure your parse server will be up-to-date. This tutorial will show you the advantages of the ApiOmat SDKs in comparison to Parse.

Initializing the SDK

In Parse you need your public and private keys to start initialization:

public void onCreate() {
...
Parse.initialize(this, "PUBLIC_KEY", "PRIVATE_KEY");
...
}

ApiOmat handles the connection data for you, just call the configure method and pass your user (see the Users section below):

public void onCreate() {
...
Datastore.configureWithCredentials(user);
...
}

Users

In Parse, you use the following code to create a user:

ParseUser user = new ParseUser();
user.setUsername("JohnDoe");
user.setPassword("123456");
user.setEmail("doe@john.org");
 
user.signUpInBackground(new SignUpCallback() {
public void done(ParseException e) {
if (e == null) {
//go on with the user
} else {
//something went wrong, eh?
}
}
});

In ApiOmat, a user is represented by the User class, which is automatically included in every backend and each ApiOmat SDK. An ApiOmat User has some unique traits available, for example, it contains the connection to the databse (one of the great features of generated SDKs), so you just have to pass the instance as parameter to the configure() method seen above.

final User user = new User();
user.setUserName("JohnDoe");
user.setPassword("123456");
user.setEmail("doe@john.org");
...
//now comes the datastore configure
...
// create the user
user.saveAsync(new AOMEmptyCallback() {
public void isDone(boolean wasLoadedFromStorage, ApiomatRequestException e) {
if (e == null) {
//go on with the user
} else {
//something went wrong, eh?
}
}
});

Arbitrary Objects

In Parse, you create objects using the ParseObject class and key values, which leads to lots of strings. To create an object "Task" with a "due date" and "done" status, you have to write the following code:

ParseObject task = new ParseObject("Task");
task.put("description", "Buy coffee");
task.put("dueDate", "05-03-13");
task.put("done", false);
task.saveInBackground();

In ApiOmat, you define your data models just one time in the backend and then generate SDKs based on your data models. So to create the same task as the Parse example, you use the task class as shown below:

Task task = new Task();
task.setDescription("Buy coffee");
task.setDueDate("05-03-13");
task.setDone(false);
task.saveAsync(...);

Queries

Parse uses a separate ParseQuery class for queries:

ParseQuery query = new ParseQuery("Task");
query.whereEqualTo("description", "coffee");
query.findInBackground(new FindCallback() {
public void done(List<parseobject> scoreList, ParseException e) {
if (e == null) {
//retrieved some results
} else {
//something went wrong, eh?
}
}
});

In ApiOmat, you can query each object with the load method:

Task.getTasksAsync("description LIKE coffee", false, new AOMCallback() {
public void isDone(List<task> tasks, boolean wasLoadedFromStorage, ApiomatRequestException exception) {
if (e == null) {
//retrieved some results
} else {
//something went wrong, eh?
}
}
}

Geographic data

In Parse, you use the ParseGeoPoint class to deal with goegraphic data:

ParseGeoPoint point = new ParseGeoPoint(70.0, 50.0);

In ApiOmat, simply select the type “Location” in you data model as attribute type and you will get methods for setting/getting the longitude and latitude in your SDK:

task.setLocationLongitude(70.0);
task.setLocationLatitude(50.0);

Sending Push messages

With Parse:

ParsePush push = new ParsePush();
push.setMessage("Hello to MyChannel");
push.sendInBackground();

With ApiOmat:

PushMessage push = new PushMessage();
push.setPayload("Hello to MyChannel");
push.saveAsync(...);

Custom business logic

Parse “Cloud Code” feature allows developers to write JavaScript methods and call them from client:

ParseCloud.callFunction("myMethod", new HashMap<object , Object>(), new FunctionCallback<string>() {
void done(String result, ParseException e) {
if (e == null) {
// ok!
}
}
});

ApiOmat also provides the ability to write custom backend logic using special hooks, which are called during request and your code is executed automatically.

Twitter

Parse lets you configure the access to your Twitter app in the client:

ParseTwitterUtils.initialize("CONSUMER KEY", "CONSUMER SECRET");
 
ParseTwitterUtils.logIn(this, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException e) {
if (user == null) {
//user cancelled the login
} else if (user.isNew()) {
//new user signed up and logged in
} else {
//user logged in
}
}
});

In ApiOmat, you apply these settings in the module config; The clients only have to call the authentication URL, everything else is done by ApiOmat

http://apiomat.com/yambas/rest/modules/Twitter/spec/YOURAPPNAME/auth

For more information, see our Twitter Module Documentation.

Facebook

Facebook login with Parse works the same way as Twitter:

ParseFacebookUtils.initialize("FACEBOOK_APP_ID");
...
ParseFacebookUtils.logIn(this, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException e) {
if (user == null) {
//user cancelled the login
} else if (user.isNew()) {
//new user signed up and logged in
} else {
//user logged in
}
}
});

Just like with Twitter, you use the ApiOmat Facebook Module and enter your credentials in the module config. The client only has to call the authentication URL, everything else is done by ApiOmat.

http://apiomat.com/yambas/rest/modules/Facebook/spec/YOURAPPNAME/auth?userId=USERID&usedSystem=SYSTEM

For more information, see our Facebook Module Documentation.

That’s it. And by the way, the code in ApiOmat SDKs is nearly the same on the other platforms (iOS, Swift, Xamarin, etc.). Despite of these examples, the main difference of ApiOmat is the complete modeling of data in the backend and our generated SDK.

* link only available in Enterprise Documentation