Building data driven mobile apps with phone gap and webapi

43

description

Raleigh Code Camp 2013 For a video of this presentation, go to http://www.codeovereasy.com

Transcript of Building data driven mobile apps with phone gap and webapi

Page 1: Building data driven mobile apps with phone gap and webapi
Page 2: Building data driven mobile apps with phone gap and webapi

Building Data Driven Mobile Apps with PhoneGap and WebAPI

Page 3: Building data driven mobile apps with phone gap and webapi

Derek Smith @smithderekm

codeovereasy.com

Page 4: Building data driven mobile apps with phone gap and webapi

There are 10 kinds

of apps in the world.

Page 5: Building data driven mobile apps with phone gap and webapi
Page 6: Building data driven mobile apps with phone gap and webapi
Page 7: Building data driven mobile apps with phone gap and webapi
Page 8: Building data driven mobile apps with phone gap and webapi
Page 9: Building data driven mobile apps with phone gap and webapi
Page 10: Building data driven mobile apps with phone gap and webapi

API APP Asp.Net WebAPI PhoneGap

Page 11: Building data driven mobile apps with phone gap and webapi

ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework.

Page 12: Building data driven mobile apps with phone gap and webapi
Page 13: Building data driven mobile apps with phone gap and webapi

Architecture

Page 14: Building data driven mobile apps with phone gap and webapi

Data Store

DAL

WebApi

JSON

HTML

jQueryMobile

CSS

Page 15: Building data driven mobile apps with phone gap and webapi

Data Store

DAL

WebApi

JSON

HTML

jQueryMobile

CSS

Page 16: Building data driven mobile apps with phone gap and webapi
Page 17: Building data driven mobile apps with phone gap and webapi

/api/account/ {POST}

Page 18: Building data driven mobile apps with phone gap and webapi

/api/outagereports/ {GET}

Page 19: Building data driven mobile apps with phone gap and webapi

/api/outagereport {POST} /api/outagereport {GET, PUT}

Page 20: Building data driven mobile apps with phone gap and webapi

/api/outagereport {DELETE}

Page 21: Building data driven mobile apps with phone gap and webapi

/api/outagereport {POST} Upload Photo & GPS Coordinates

Page 22: Building data driven mobile apps with phone gap and webapi

http://www.flickr.com/photos/steevithak/

Demo {structure}

Page 23: Building data driven mobile apps with phone gap and webapi

Cross-origin resource sharing (CORS) is a mechanism that allows JavaScript on a web page to make XMLHttpRequests to another domain, not the domain the JavaScript originated from.

http://en.wikipedia.org/wiki/Cross-origin_resource_sharing

Page 24: Building data driven mobile apps with phone gap and webapi
Page 25: Building data driven mobile apps with phone gap and webapi

http://www.flickr.com/photos/steevithak/

Demo {CORS}

Page 26: Building data driven mobile apps with phone gap and webapi

Authentication

Page 27: Building data driven mobile apps with phone gap and webapi

•Cookie Based

•WebApi has no UI Forms

•HTTP header

•Plaintext on wire Basic

•3 step

•Token passed on header Token

Page 28: Building data driven mobile apps with phone gap and webapi

Client

Authorization Server

Resource Server

POST Authorization Basic

401 Unauthorized

GET

200 TOKEN

POST Authorization Bearer: TOKEN

200

/api/account

/api/report

Page 29: Building data driven mobile apps with phone gap and webapi

Enable Token Support on Web API

Page 30: Building data driven mobile apps with phone gap and webapi

Enable Token Support on Web API

Add Token Method to Controller

Page 31: Building data driven mobile apps with phone gap and webapi

Enable Token Support on Web API

Add Token Method to Controller

Update client Logon to get Token

Page 32: Building data driven mobile apps with phone gap and webapi

Enable Token Support on Web API

Add Token Method to Controller

Update client Logon to get Token

Update API calls to pass token

Page 33: Building data driven mobile apps with phone gap and webapi

http://www.flickr.com/photos/steevithak/

Demo {Authentication}

Page 34: Building data driven mobile apps with phone gap and webapi

Device Features

Page 35: Building data driven mobile apps with phone gap and webapi

PhoneGap Plugin Model

$ phonegap local plugin add org.apache.cordova.device $ phonegap local plugin add org.apache.cordova.camera $ phonegap local plugin add org.apache.cordova.geolocation $ phonegap local plugin list [phonegap] org.apache.cordova.camera [phonegap] org.apache.cordova.device [phonegap] org.apache.cordova.geolocation

Page 36: Building data driven mobile apps with phone gap and webapi
Page 37: Building data driven mobile apps with phone gap and webapi

/api/outagereport {POST} /api/outagereportphoto

{POST} Upload Photo & GPS Coordinates

Page 38: Building data driven mobile apps with phone gap and webapi

http://www.flickr.com/photos/steevithak/

Demo {DEVICE FEATURES}

Page 39: Building data driven mobile apps with phone gap and webapi

Headache #1: Cross Origin Resource Sharing

Page 40: Building data driven mobile apps with phone gap and webapi

Headache #2: <access origin =“*”/>

Page 41: Building data driven mobile apps with phone gap and webapi

Headache #3: Emulator networking

Page 42: Building data driven mobile apps with phone gap and webapi

• http://docs.phonegap.com • http://coenraets.org/blog/phonegap-tutorial/ • Telerik Icenium – newly release

implementation IDE of Cordova

Page 43: Building data driven mobile apps with phone gap and webapi

Good luck!