AN IPHONE-PYTHON                              LOVE AFFAIR                             Building APIs for MobileWednesday, J...
Music Hack Day, February 2011                                Samantha & MattWednesday, June 8, 2011
ACCOMPLICE #1                     Anna Callahan: iOS developer, jazz trumpet player                                       ...
ACCOMPLICE #2             Nate Aune: Django/Python/Plone developer, saxophonist                                   @nateaWe...
VALENTUN.ES!Wednesday, June 8, 2011
Wednesday, June 8, 2011
MOBILE TAKEOVER                If you’re not building for mobile now, you will be soon.Wednesday, June 8, 2011
WHAT’S DIFFERENT ABOUT                   MOBILE?    • Isn’t        REST appropriate for everything?    • Don’t            ...
WHAT’S DIFFERENT ABOUT                   MOBILE?                          Mobile users are unwilling to wait.       1. Con...
SO YOUR API SHOULD    • Return              hierarchies of related data    • Authentication              and Authorization...
HIERARCHIES OF DATA                          Bad :(        Good!             Cards             TracksWednesday, June 8, 2011
CARD CLASSWednesday, June 8, 2011
TRACK CLASSWednesday, June 8, 2011
SIMPLE REST API                          Basic CRUD operations via API.Wednesday, June 8, 2011
URLS.PY   Now access cards and tracks with /api/card/ and /api/track/Wednesday, June 8, 2011
CREATE A CARDWednesday, June 8, 2011
WHAT ABOUT TRACKS?          Default post_list from resources.py (create object via POST)Wednesday, June 8, 2011
WHAT ABOUT TRACKS?                          api.py post_list (override method)Wednesday, June 8, 2011
MOBILE WANTS                          HIERARCHICAL DATAWednesday, June 8, 2011
TASTYPIE MAKES IT EASYWednesday, June 8, 2011
AUTHENTICATION &                           AUTHORIZATION                          Authentication - let the user in the doo...
LIMITING BY USER            Returns only the objects owned by the current user.Wednesday, June 8, 2011
ERROR CODES       Ideally your API should:        •Never return HTML        •Tailor response codes to actions on device   ...
JSON ERROR RESPONSES                     override wrap_view from resources.pyWednesday, June 8, 2011
JSON ERROR HANDLING                          Objective-C in XcodeWednesday, June 8, 2011
Wednesday, June 8, 2011
ACCEPT ARRAYS OF DATA    • User           enters tunnel    • User           uses your app    • User           closes your ...
PRE-CALCULATED DATA OR           DATA NOT STORED ON                 DEVICE    • No   other users are stored       on devic...
THANK YOU!    • Music   Hack Day Accomplices: Matt Katz, Alexandre Passant,       Jeff Novich, Twom Deryckere    • Danielz...
MORE INFO    • Valentun.es   live site       http://valentun.es    • Valentunes    (Django code)       https://github.com/...
DJANGO API FRAMEWORKS    • TastyPie   documentation (the one we used)       http://readthedocs.org/docs/django-tastypie/en...
Upcoming SlideShare
Loading in …5
×

iPhone Python love affair

2,978 views

Published on

How to build an API for mobile devices in Django using Tastypie.

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,978
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
0
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

iPhone Python love affair

  1. 1. AN IPHONE-PYTHON LOVE AFFAIR Building APIs for MobileWednesday, June 8, 2011
  2. 2. Music Hack Day, February 2011 Samantha & MattWednesday, June 8, 2011
  3. 3. ACCOMPLICE #1 Anna Callahan: iOS developer, jazz trumpet player @jazztptWednesday, June 8, 2011
  4. 4. ACCOMPLICE #2 Nate Aune: Django/Python/Plone developer, saxophonist @nateaWednesday, June 8, 2011
  5. 5. VALENTUN.ES!Wednesday, June 8, 2011
  6. 6. Wednesday, June 8, 2011
  7. 7. MOBILE TAKEOVER If you’re not building for mobile now, you will be soon.Wednesday, June 8, 2011
  8. 8. WHAT’S DIFFERENT ABOUT MOBILE? • Isn’t REST appropriate for everything? • Don’t I want a single API for all clients?Wednesday, June 8, 2011
  9. 9. WHAT’S DIFFERENT ABOUT MOBILE? Mobile users are unwilling to wait. 1. Connection = slow, spotty, or non-existent 2. Mobile is not as powerful at fetching & saving data or calculationsWednesday, June 8, 2011
  10. 10. SO YOUR API SHOULD • Return hierarchies of related data • Authentication and Authorization • Have mobile-specific error codes & messages • Accept arrays of related or unrelated data • Return pre-calculated data or data that doesn’t exist on deviceWednesday, June 8, 2011
  11. 11. HIERARCHIES OF DATA Bad :( Good! Cards TracksWednesday, June 8, 2011
  12. 12. CARD CLASSWednesday, June 8, 2011
  13. 13. TRACK CLASSWednesday, June 8, 2011
  14. 14. SIMPLE REST API Basic CRUD operations via API.Wednesday, June 8, 2011
  15. 15. URLS.PY Now access cards and tracks with /api/card/ and /api/track/Wednesday, June 8, 2011
  16. 16. CREATE A CARDWednesday, June 8, 2011
  17. 17. WHAT ABOUT TRACKS? Default post_list from resources.py (create object via POST)Wednesday, June 8, 2011
  18. 18. WHAT ABOUT TRACKS? api.py post_list (override method)Wednesday, June 8, 2011
  19. 19. MOBILE WANTS HIERARCHICAL DATAWednesday, June 8, 2011
  20. 20. TASTYPIE MAKES IT EASYWednesday, June 8, 2011
  21. 21. AUTHENTICATION & AUTHORIZATION Authentication - let the user in the door Authorization - what the user can seeWednesday, June 8, 2011
  22. 22. LIMITING BY USER Returns only the objects owned by the current user.Wednesday, June 8, 2011
  23. 23. ERROR CODES Ideally your API should: •Never return HTML •Tailor response codes to actions on device •Return messages designed for the end user •Never, ever return HTMLWednesday, June 8, 2011
  24. 24. JSON ERROR RESPONSES override wrap_view from resources.pyWednesday, June 8, 2011
  25. 25. JSON ERROR HANDLING Objective-C in XcodeWednesday, June 8, 2011
  26. 26. Wednesday, June 8, 2011
  27. 27. ACCEPT ARRAYS OF DATA • User enters tunnel • User uses your app • User closes your app • User exits tunnelWednesday, June 8, 2011
  28. 28. PRE-CALCULATED DATA OR DATA NOT STORED ON DEVICE • No other users are stored on device • Leaderboards or other calculated user data must come from the serverWednesday, June 8, 2011
  29. 29. THANK YOU! • Music Hack Day Accomplices: Matt Katz, Alexandre Passant, Jeff Novich, Twom Deryckere • Danielzilla (Daniel Lindsley) - TastyPie • IsaacKelly • DjangoConWednesday, June 8, 2011
  30. 30. MORE INFO • Valentun.es live site http://valentun.es • Valentunes (Django code) https://github.com/natea/valentunes • Valentunes (iPhone code) https://github.com/jazztpt/Valentunes_iPhone • Valentunes (Twilio integration) https://github.com/terraces/valentunes-twilioWednesday, June 8, 2011
  31. 31. DJANGO API FRAMEWORKS • TastyPie documentation (the one we used) http://readthedocs.org/docs/django-tastypie/en/latest/ • django-piston https://bitbucket.org/jespern/django-piston/ • Django REST framework http://django-rest-framework.orgWednesday, June 8, 2011

×