web api for mobile jaxarcsig april 2012. about me david fekke l.l.c. mobile apps for ios regular...
TRANSCRIPT
![Page 1: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/1.jpg)
Web API for MobileJaxARCSIG April 2012
![Page 2: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/2.jpg)
About Me
David Fekke L.L.C.
Mobile apps for iOS
Regular presenter at JaxDUG, JSSUG and JaxFusion
Writing Web Services for over 10 years
![Page 3: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/3.jpg)
![Page 4: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/4.jpg)
History of Web Services
1989 - Tim Berners-Lee invents HTTP/HTML
1998 - XML 1.0, SOAP begins ratification
2001 - SOAP standard
2000 - Fielding dissertation on REST
![Page 5: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/5.jpg)
SOAP
Simple Object Access Protocol
Uses a standard XML Schema over HTTP
Extremely cross platform compatible
Extremely Slow
![Page 6: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/6.jpg)
REST
Representable State Transfer
Uses standard HTTP
Can use any text format including XML
![Page 7: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/7.jpg)
XML vs JSON
XML tag based document formatting
Javascript Notation by Douglas Crockford
JSON less verbose than XML, more lightweight
Mobile devices have limited bandwidth
![Page 8: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/8.jpg)
Public APIs
Flickr
Amazon
iTunes
![Page 9: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/9.jpg)
WebAPI
Available now as Nuget Package
Built-in as part of MVC 4
Take advantage of HTTP features directly
![Page 10: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/10.jpg)
HTTP methods as Actions
Default route will use http method for action
Controller/action/id
API/Controller/id GET/POST/PUT/DELETE
![Page 11: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/11.jpg)
HTTP Method meanings
Get - Return an existing document
Post - Create a new document
Put - Update a document
Delete - Self explanatory
![Page 12: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/12.jpg)
Configure Transport
Set Xml or JSON based on Content-Type or Accept header
Accept: application/xml
Can also use Odata
![Page 13: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/13.jpg)
Return Codes
Now have the ability to specify return codes beside 200
HttpResponseMessage<YourEntity>
HttpStatusCode.Created 201
response.Headers.Location = new Uri()
![Page 14: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/14.jpg)
Http Status codes
201 Created
200 Success/204 Success but No Content
403 Not authorized
404 Does not exist
500 Server Error
301 Uri Moved
![Page 15: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/15.jpg)
Security
[Authorize()]
https over port 443
Security Tokens
OAuth
![Page 16: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/16.jpg)
Testing WebAPI
Download Fiddler2
Firebug (Firefox)
Chrome
On Mac use CocoaRestClient
![Page 17: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/17.jpg)
Consuming WebAPI
Web Apps (ASP.NET, MVC, PHP, Java, ColdFusion, Ruby(Rails), Python, Perl(if you are masochistic))
JavaScript/JQuery
Mobile (iOS, Android, WP7, Blackberry OS)
![Page 18: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/18.jpg)
Develop WebAPI and iOS on Same
Computer
Parallels or VMWare
Set Network Adapter to Bridged
Run Visual Studio as Administrator
Host on IIS (do not use IIS Express or Casini)
![Page 19: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/19.jpg)
Consuming WebAPI in iOS
Use NSURLConnection delegate or GCD
Show progress while waiting on response
Use JSON over XML
NSJSONSerialization class (new in iOS 5)
![Page 20: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/20.jpg)
XML Parsing in iOSNSXMLParser (Slowest)
libxml2 (C api)
TBXML (DOM, Fastest, no write or xpath)
TouchXML (DOM supports xpath, no write)
KissXML (based on Touch, can write)
GDataXML (DOM, from Google)
RaptureXML (DOM, supports xpath)
![Page 21: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/21.jpg)
Call WebAPI from Android
Create DefaultHttpClient();
Create request with HttpGet(Url);
Create response handler BasicResponseHandler();
httpClient.execute(request, handler);
![Page 22: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/22.jpg)
JSON in Android
use the JSONObject to parse
JSONObject jo = new JSONObject(jString);
jo.getJSONObject(“car”);
jo.getJSONArray(“cars”);
![Page 23: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/23.jpg)
XML Parsing in Android
DOM, SAX and Pull
W3C Dom parser
Standard Java Sax Parser
SJXP (Pull parser)
![Page 24: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/24.jpg)
WebAPI as persistence
Don’t use WebAPI as default persistence on Mobile
Both Android and iOS have device persistence
local storage, CoreData and SQLite
iCloud to sync between iOS devices
![Page 25: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/25.jpg)
Demo
![Page 26: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/26.jpg)
Questions
![Page 27: Web API for Mobile JaxARCSIG April 2012. About Me David Fekke L.L.C. Mobile apps for iOS Regular presenter at JaxDUG, JSSUG and JaxFusion Writing Web](https://reader035.vdocument.in/reader035/viewer/2022062421/56649d165503460f949ebfad/html5/thumbnails/27.jpg)
Contact Info
David Fekke
fekke.com/blog
david fekke at gmail dot com
twitter @davidfekke
aim: davefekke