EECS 394 Software Development Chris Riesbeck Developing Mobile/Web - - PowerPoint PPT Presentation

eecs 394
SMART_READER_LITE
LIVE PREVIEW

EECS 394 Software Development Chris Riesbeck Developing Mobile/Web - - PowerPoint PPT Presentation

EECS 394 Software Development Chris Riesbeck Developing Mobile/Web Apps 1 Wednesday, October 24, 2012 Mobile Choices 2 Wednesday, October 24, 2012 Native Apps Native app access to all phone features best look and feel and performance


slide-1
SLIDE 1

Chris Riesbeck

EECS 394

Software Development

Developing Mobile/Web Apps

1 Wednesday, October 24, 2012

slide-2
SLIDE 2

Mobile Choices

2 Wednesday, October 24, 2012

slide-3
SLIDE 3

Native Apps

Native app access to all phone features best look and feel and performance BUT non-portable development platforms: iPhone: Objective-C Android: Java

3 Wednesday, October 24, 2012

slide-4
SLIDE 4

Mobile App Requirements

iPhone requirements: Mac with Snow Leopard (Lion?) XCode IDE and libraries iPhone SDK, developer license iPhone to deploy Android requirements: Windows / Linux / Macs Eclipse IDE recommended Android SDK phone recommended but emulator works

4 Wednesday, October 24, 2012

slide-5
SLIDE 5

PhoneGap / Cordova

Portable framework for iPhone, Android, Blackberry, .. Runs as a native app, but coded HTML5 + CSS + Javascript Same requirements as native development iPhone: XCode, iPhone SDK, iPhone... Android: Eclipse, Java, Android SDK, ...

5 Wednesday, October 24, 2012

slide-6
SLIDE 6

Resources: PhoneGap

http://www.phonegap.com/ http://incubator.apache.org/cordova/ Videos Early, non-slick 3 minute spiel on PhoneGap 9-minute demo converting HTML to iPhoneApp Discussion groups http://groups.google.com/group/phonegap http://phonegapforum.com/ (books) http://www.amazon.com/s/ref=nb_sb_noss_1? url=search-alias%3Daps&field-keywords=phonegap

6 Wednesday, October 24, 2012

slide-7
SLIDE 7

Web Pages

Web page multi-platform, easily tested

  • nly needs HTML/CSS/Javascript skills

BUT limited access to phone features feels like a web page

7 Wednesday, October 24, 2012

slide-8
SLIDE 8

Mobile Web Pages

HTML5 + CSS + Javascript support touch gestures access to some phone features can adapt to multiple screen sizes http://www.html5rocks.com/en/mobile/mobifying/ provides local data store – critical for offline use http://www.ibm.com/developerworks/web/library/wa-

  • fflineweb/index.html

animations can be hardware optimized http://www.html5rocks.com/en/mobile/optimization-and- performance/

8 Wednesday, October 24, 2012

slide-9
SLIDE 9

Mobile Web Page Resources

http://sixrevisions.com/web-applications/ building-mobile-web-apps-the-right-way-tips- and-techniques/ http://www.html5rocks.com/en/mobile/ mobifying/ http://www.ibm.com/developerworks/web/ library/wa-offlineweb/index.html http://www.html5rocks.com/en/mobile/

  • ptimization-and-performance/

9 Wednesday, October 24, 2012

slide-10
SLIDE 10

Mobile Web Page Frameworks

http://css.dzone.com/articles/building-mobile- web http://mashable.com/2010/08/18/mobile-web- app-frameworks/ (book ad) http://www.sitepoint.com/books/ mobile1/

10 Wednesday, October 24, 2012

slide-11
SLIDE 11

web App Tips

Develop and test in Webkit browsers Chrome or Safari <!DOCTYPE HTML> Validate constantly! HTML: http://validator.w3.org/ CSS: http://jigsaw.w3.org/css-validator/ Javascript: http://www.jslint.com/

11 Wednesday, October 24, 2012

slide-12
SLIDE 12

RESTful Web Apps

12 Wednesday, October 24, 2012

slide-13
SLIDE 13

Has this ever happened to you?

13

You select an item from a menu. The browser shows data about that item.

Wednesday, October 24, 2012

slide-14
SLIDE 14

Has this ever happened to you?

13

You select an item from a menu. The browser shows data about that item. You click the back button to see something else. A scary dialog box asks if you want to resubmit data to the server.

Wednesday, October 24, 2012

slide-15
SLIDE 15

Has this ever happened to you?

13

You select an item from a menu. The browser shows data about that item. I'm talking to you, CAESAR. You click the back button to see something else. A scary dialog box asks if you want to resubmit data to the server.

Wednesday, October 24, 2012

slide-16
SLIDE 16

Has this ever happened to you?

13

You select an item from a menu. The browser shows data about that item. I'm talking to you, CAESAR. You bookmark that page for future reference. Later, you click the bookmark. The browser takes you to the main page instead. You click the back button to see something else. A scary dialog box asks if you want to resubmit data to the server.

Wednesday, October 24, 2012

slide-17
SLIDE 17

Has this ever happened to you?

13

You select an item from a menu. The browser shows data about that item. I'm talking to you, CAESAR. I'm talking to you, Blackboard. You bookmark that page for future reference. Later, you click the bookmark. The browser takes you to the main page instead. You click the back button to see something else. A scary dialog box asks if you want to resubmit data to the server.

Wednesday, October 24, 2012

slide-18
SLIDE 18

How the web works

14 Wednesday, October 24, 2012

slide-19
SLIDE 19

How the web works

14

(slightly simplified)

Wednesday, October 24, 2012

slide-20
SLIDE 20

How the web works

14

(slightly simplified) POST + form data Browser Server GET + URL

Clicking a link: Submitting a form:

Wednesday, October 24, 2012

slide-21
SLIDE 21

How the web works

14

(slightly simplified) POST + form data Browser Server GET + URL

Clicking a link: Submitting a form:

HTML + CSS + media Server Browser

Wednesday, October 24, 2012

slide-22
SLIDE 22

How the web works

14

(slightly simplified) POST + form data Browser Server GET + URL

Clicking a link: Submitting a form:

HTML + CSS + media Server Browser

GET and POST are very different actions for the browser.

Wednesday, October 24, 2012

slide-23
SLIDE 23

How the web works

14

(slightly simplified) POST + form data Browser Server GET + URL

Clicking a link: Submitting a form:

HTML + CSS + media Server Browser

GET and POST are

  • ften handled by

the same code on the server. GET and POST are very different actions for the browser.

Wednesday, October 24, 2012

slide-24
SLIDE 24

How the web works

14

(slightly simplified) POST + form data Browser Server GET + URL

Clicking a link: Submitting a form:

HTML + CSS + media Server Browser

GET and POST are

  • ften handled by

the same code on the server. GET and POST are very different actions for the browser. But POST may modify state, GET should not

Wednesday, October 24, 2012

slide-25
SLIDE 25

HTTP method types

15

POST GET, HEAD

Wednesday, October 24, 2012

slide-26
SLIDE 26

HTTP method types

15

repeated calls get the same results Idempotent

  • nly retrieves data

Safe POST GET, HEAD

Wednesday, October 24, 2012

slide-27
SLIDE 27

HTTP method types

15

repeated calls get the same results Idempotent

  • nly retrieves data

Safe POST GET, HEAD Neither Ergo, browsers ask before repeating

Wednesday, October 24, 2012

slide-28
SLIDE 28

retrieve a resource

Why the web works

16

stable unique bookmarkable URLs

GET

server state = a collection of resources

Resources

update server state

POST

safe, stateless, re-execute at any time not safe to re-execute

The web scaled because sites are mostly repositories of self-describing resources, not applications.

Roy Fielding "Architectural Styles and the Design of Network-based Software Architectures" (PhD, UCI, 2000)

Wednesday, October 24, 2012

slide-29
SLIDE 29

provide an initial unchanging home URL with links to other resources

RESTful web apps

17

define as much of your system as possible in terms of resources (lists, item details, carts, user profiles, ...) use POST (and/or PUT and DELETE) to update resources

(REpresentational State Transfer)

make all resources available via some chain of links starting from the home page use GET to retrieve resources

Wednesday, October 24, 2012

slide-30
SLIDE 30

Common mistake #1

18

Example: the PHP tutorial's demo blog has a delete link next to each blog entry

A link (GET) that updates a resource.

A web crawler, e.g., Google, a site map generator, a broken link finder, even a browser pre-fetch loop, will delete every blog entry!

Use a form with POST for all actions that modify server state.

Fix Bug

Wednesday, October 24, 2012

slide-31
SLIDE 31

Common mistake #2

19

Example: a search field

A form (POST) that just gets a resource.

Search results can't be bookmarked. Going back to the results page triggers "do you want to resend data?"

Fix

Use form with GET method Use POST-REDIRECT-GET pattern

Bug

Wednesday, October 24, 2012

slide-32
SLIDE 32

POST-REDIRECT-GET

20

Client Server

http://blog.andreloker.de/post/2008/06/Post-Redirect-Get.aspx

Wednesday, October 24, 2012

slide-33
SLIDE 33

POST-REDIRECT-GET

20

Client Server POST + form data

http://blog.andreloker.de/post/2008/06/Post-Redirect-Get.aspx

Wednesday, October 24, 2012

slide-34
SLIDE 34

POST-REDIRECT-GET

20

Client Server POST + form data Redirect to URL GET + URL

http://blog.andreloker.de/post/2008/06/Post-Redirect-Get.aspx

Wednesday, October 24, 2012

slide-35
SLIDE 35

POST-REDIRECT-GET

20

Client Server POST + form data Redirect to URL GET + URL

no "resubmit?" on browser back after update, redirect browser to resource with results http://blog.andreloker.de/post/2008/06/Post-Redirect-Get.aspx invisible to user

Wednesday, October 24, 2012

slide-36
SLIDE 36

Agile Rest

21

REST solutions are fast solutions Example: don't create user accounts, create user-specific URLs no need to implement authentication no friction for users "I'm not giving these guys my email (Facebook access, ...)" "Cripes, another password to keep track of..." URL for user's home page, video stream, circle of friends Trivial to implement or do by hand Easy to add authentication and access control later Much easier to test with test scripts Examples: join.me and Google+ Hangout

Wednesday, October 24, 2012

slide-37
SLIDE 37

Single Page Apps

22

Single Page App: all or almost all interaction

  • ccurs on a single web page

Apparent multiple pages actually DIV's hidden and shown using Javascript and CSS Data retrieved using XHR (XMLHttpRequest), a.k.a. AJAX (asynchronous Javascript and XML) POST-REDIRECT-GET not needed with XHR

Wednesday, October 24, 2012

slide-38
SLIDE 38

RESTful APIs

23

URL's for XHR calls designed following RESTful principles GET to retrieve data with no change in server state POST to modify server state Also PUT and DELETE Decouples the service from the client Enables wider user of the service, e.g., mashups

Wednesday, October 24, 2012