Top Banner
LoopBack: An Easy and Robust Mobile Backend Aviv Callander and Michael Hantler www.hi-techconsulting.net
31

Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Jul 16, 2015

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

LoopBack: An Easy and

Robust Mobile BackendAviv Callander and Michael Hantler

www.hi-techconsulting.net

Page 2: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

PERFECTED TECHMobile App Development Perfected Inside And Out

Page 3: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Aviv Callander

CEO of a software development firm in Jerusalem Israel with focus on mobile

and web. With over 10 years of high-tech experience Aviv has managed,

designed and developed full software cycles for successful high-tech

companies globally.

Page 4: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Michael Hantler

Michael started developing for mobile platforms (Android, iOS, BlackBerry,

mobile web) in 2010 with a focus on developing applications for the Android

operating system. His specialties include UX design and integration,

application architecture, hybrid app development, secure enterprise

development, data security, cloud-based-data integration, and robust POC

implementations.

Page 5: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

The Need for Cloud on Mobile

Page 6: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

What is LoopBack?

Open Source API Framework

Node.js

Mobile SDKs

Model Driven Development

Page 7: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Server Setup

Page 8: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting
Page 9: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting
Page 10: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting
Page 11: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting
Page 12: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting
Page 13: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Custom Server Setup

Page 14: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Server Complete!

Page 15: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

LoopBack Client SDKs

Page 16: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

SDKs, We don’t need no stinking SDKs

Page 17: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

A Look at the Client SDKs

iOS

Android

Android Deeper Look

Browser Javascript (Angular)

Client example

All information available through LoopBack documentation and LoopBacks open source GitHub

Repos.

Page 18: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

iOS SDK

AFNetworking

Open source on GitHub

Page 19: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

iOS SDK

AFNetworking

Open source on GitHub

Notes

@interface WidgetRepository : LBModelRepository

@interface Widget : LBModel

Page 20: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

iOS Sample Code

NSURL serverURL = [NSURL URLWithString:@"http://example.com"];

LBRESTAdapter *adapter = [LBRESTAdapter adapterWithURL:serverURL];

Connect Adapter to LoopBack Node.js instance

WidgetRepository *repository = (WidgetRepository *)[adapter repositoryWithModelClass:[WidgetRepository

class]];

Widget *pencil = (Widget *)[repository modelWithDictionary:@{ @"name": @"Pencil", @"price": @1.50 }];

Create repository instance and a new instance of a pencil

Page 21: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

iOS Sample Code cont

[pencil saveWithSuccess:^{// Pencil now exists on the server!

}failure:^(NSError *error) {

NSLog("An error occurred: %@", error);}];

Now save that pencil instance to the server

Page 22: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Android SDK

loopj/Asynchronous Http Client

min-sdk 8

Open source on github

Notes

public class WidgetRepository extends ModelRepository<Widget>

public class Widget extends Model

Page 23: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Android Sample Code

Connect Adapter to LoopBack node.js Instance

RestAdapter adapter = new RestAdapter(getApplicationContext(), "http://example.com");

WidgetRepository repository = adapter.createRepository(WidgetRepository.class);

Create repository instance

Page 24: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Android Sample Code Cont

repository.findById(1, new ModelRepository.FindCallback<Widget>() {@Overridepublic void onSuccess(Widget widget) {

// found my iPencil!}

public void onError(Throwable t) {// handle the error

}});

Now to grab our pencil from the server (lets assume it had an id of 1)

Page 25: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Android SDK: Deeper Look

import java.math.BigDecimal;import com.strongloop.android.loopback.Model;

/*** A widget for sale.*/public class Widget extends Model {

private String name;private BigDecimal price;

public void setName(String name) {this.name = name;

}

public String getName() {return name;

}

public void setPrice(BigDecimal price) {this.price = price;

}

public BigDecimal getPrice() {return price;

}}

Page 26: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Android SDK: Deeper Look cont.

public class WidgetRepository extends ModelRepository<Widget> {public WidgetRepository() {

super("widget", Widget.class);}

}

Page 27: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Build the AngularJS module lbServices VIA SDK

lb-ng route/to/loopbackjs/startfile/app.js route/to/create/lbservices.js

If your solution hosting and running the AngularJS app is elsewhere?

Browser JavaScript (Angular)

Page 28: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Register the AngularJS module lbServices

angular.module('my-app-module',['ngRoute' /* etc */, 'lbServices', 'my-app.controllers'])

Create a User from controller

module.controller('RegisterCtrl', function($scope, User, $location) {var creatingUser = {

firstName: $scope.profile.firstName,lastName: $scope.profile.lastName// etc ...

};

User.create(creatingUser).$promise.then(function(createdUser){if(createdUser){

// continue to something great...}

});});

Browser JavaScript (Angular)

Page 29: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Angular example

User.login({include: 'user', rememberMe: false }, credentials, function(data) {

console.log('Successful Login');$location.path('/dashboard');

}else{

console.log('Failed Login');$location.path('/notification/failedLogin');

}

}, function(response) {

console.log('Failed Login');$location.path('/notification/failedLogin');

});

Page 30: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Todo.find({ filter: { where: { or: [{isActive: true }, {randomFakeParam: true }] } } }).$promise.then(function(data){

});

Todo.find({ filter: { limit: 10 } }).$promise.then(function(data) {

});

Todo.find().$promise.then(function(data){

});

User.findOne({filter: {where: {email: '[email protected]'}}).$promise.then(function(data) {

});

Angular example

Page 31: Loopback: An Easy and Robust Mobile Backend - Michael Hantler & Aviv Callander, Hitech Consulting

Questions?