SlideServe
Menu
Préférences
© SlideServe · v2026

Mastering Web API for Mobile: Best Practices & Implementation Tips

holden avatar
27 diapositives · 411 Views · Oct 03, 2014

Discover the history, advantages, and practical usage of Web API for mobile applications, with a focus on REST vs. SOAP, JSON vs. XML, public APIs, HTTP methods, security measures, consuming APIs in iOS and Android, and more. Learn how to optimize performance, configure transport settings, correctly handle return codes, and leverage HTTP features effectively. Uncover techniques for consuming Web API in iOS and Android, as well as best practices for developing and testing in various platforms. Get tips for successful integration and persistence, and explore demo questions and contact details for additional support.

Mastering Web API for Mobile: Best Practices & Implementation Tips - slide 1
01 / 27Mastering Web API for Mobile: Best Practices & Implementation Tips
1 / 17

Télécharger la présentation

Mastering Web API for Mobile: Best Practices & Implementation Tips
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Web API for Mobile • JaxARCSIG April 2012

  2. 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

  3. 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

  4. SOAP • Simple Object Access Protocol • Uses a standard XML Schema over HTTP • Extremely cross platform compatible • Extremely Slow

  5. REST • Representable State Transfer • Uses standard HTTP • Can use any text format including XML

  6. 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

  7. Public APIs • Twitter • Facebook • Flickr • Amazon • iTunes

  8. WebAPI • Available now as Nuget Package • Built-in as part of MVC 4 • Take advantage of HTTP features directly

  9. HTTP methods as Actions • Default route will use http method for action • Controller/action/id • API/Controller/id GET/POST/PUT/DELETE

  10. HTTP Method meanings • Get - Return an existing document • Post - Create a new document • Put - Update a document • Delete - Self explanatory

  11. Configure Transport • Set Xml or JSON based on Content-Type or Accept header • Accept: application/xml • Can also use Odata

  12. Return Codes • Now have the ability to specify return codes beside 200 • HttpResponseMessage<YourEntity> • HttpStatusCode.Created 201 • response.Headers.Location = new Uri()

  13. 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

  14. Security • [Authorize()] • https over port 443 • Security Tokens • OAuth

  15. Testing WebAPI • Download Fiddler2 • Firebug (Firefox) • Chrome • On Mac use CocoaRestClient

  16. 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)

  17. 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)

  18. 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)

  19. XML Parsing in iOS • NSXMLParser (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)

  20. Call WebAPI from Android • Create DefaultHttpClient(); • Create request with HttpGet(Url); • Create response handler BasicResponseHandler(); • httpClient.execute(request, handler);

  21. JSON in Android • use the JSONObject to parse • JSONObject jo = new JSONObject(jString); • jo.getJSONObject(“car”); • jo.getJSONArray(“cars”);

  22. XML Parsing in Android • DOM, SAX and Pull • W3C Dom parser • Standard Java Sax Parser • SJXP (Pull parser)

  23. 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

  24. Demo

  25. Questions

  26. Contact Info • David Fekke • fekke.com/blog • david fekke at gmail dot com • twitter @davidfekke • aim: davefekke