The Anatomy of AppsHow iPhone, Android & Facebook Apps Consume APIsEd Anuff@edanuffSam Ramji@sramjiBrian Mulloy@landlessne...
groups.google.com/group/api-craft
youtube.com/apigee
New!       IRC Channel         #api-craft
App    App             App       World of          API   Internal               App                          APIUser   Sto...
Dogs API/dogs/ownersAuthorizationOAuth 2.0RESTful API Design - Second Editionhttp://www.youtube.com/watch?v=QpAhXa12xvU
Build an iPhone App, an Android App and aFacebook Web App**Ruby on Rails app hosted on Herokuhttp://devcenter.heroku.com/a...
App    App             App       World of          API   Internal               App                          APIUser   Sto...
Start with a basic HTTP request
AndroidHttpClient client = new DefaultHttpClient();HttpGet httpGet = new HttpGet("http://api.apizoo.com/v1/dogs");HttpResp...
Parse the data
AndroidJSONObject dogs = new JSONObject(response);iOSimport "JSONKit.h"NSDictionary *dogs = [response objectFromData];Ruby...
Resource Object Mapping
RouteMapUse
Android Spring MobileRouterequestEntity = new HttpEntity<Object>(requestHeaders);ResponseEntity<Dog> responseEntity =   re...
Android Spring MobileMap// Handled with introspection
Android Spring MobileUseDog dog = responseEntity.getBody()
iOS RestKitRoute#import <RestKit/RestKit.h>RKObjectManager* manager = [RKObjectManager   objectManagerWithBaseURL:@"http:/...
iOS RestKitMap@implementation Dog+ (NSDictionary*)elementToPropertyMappings {   return [NSDictionary dictionaryWithKeysAnd...
iOS RestKitUseDog* dog = [Dog object];dog.name = @"Rover";Dog.color = @"red";[[RKObjectManager sharedManager] postObject:d...
Ruby on Rails ActiveResourceRouteresource :dogs
Ruby on Rails ActiveResourceMapclass Dog < ActiveResource::Base self.site = "http://api.apizoo.com/v1"end
Ruby on Rails ActiveResourceUsedog = Dog.new name: ‘Rover’, color: ‘red’dog.savedog.destroy
Cache the response in a database
Android Jersey + JacksonUsageRoll your own
iOS RestKit + Core DataUsage#import <RestKit/CoreData/CoreData.h>RKObjectManager* manager = [RKObjectManager   objectManag...
Ruby on Rails ActiveResource + ActiveRecordUsageclass DogResource < ActiveResource::Base self.site = http://api.apizoo.com...
Simple to do list
Problem: we want new capabilities in our app notsupported by APIs.
Usergrid - Data & Querieshttp://www.youtube.com/watch?v=zLl56sU5Bt0
Androidusergrid_ sdkiOSUse RESTKitRuby on RailsProbably not applicable
What about offline cases
AndroidRoll your owniOS-(BOOL)reachable {Reachability *r = [Reachability    reachabilityWithHostName:@"api.apizoo.com/v1"]...
Get authorization out of the wayAssumption: the APIs we consume use OAuth 2
AndroidRoll your own
iOS RestKitRKObjectManager* objectManager = [RKObjectManager sharedManager];objectManager.client.baseURL = @”api.apizoo.co...
Ruby on Rails Oauth Gem@consumer=OAuth::Consumer.new("key","secret", site: "api.apizoo.com/v1")@request_token=@consumer.ge...
AndroidBuilt-in JSON, etc.Spring Mobile (bundles Jersey & Jackson)iOSJSONKitRestKitCore DataRuby on RailsYAJLActiveResourc...
Coming Up: March Miniseries on Apps & APIs
Questions?
THANK YOUSubscribe to API webinars at:youtube.com/apigee
THANK YOUChat on IRC#api-craft
THANK YOUQuestions and ideas to:groups.google.com/group/api-craft
THANK YOUContact us at:@edanuffed@apigee.com@sramjisramji@apigee.com@landlessnessbrian@apigee.com
Upcoming SlideShare
Loading in...5
×

The Anatomy of Apps - How iPhone, Android & Facebook Apps Consume APIs

6,540

Published on

Building mobile apps is different from building web apps. Developers need to understand the unique demands that mobile apps place on APIs and considerations across different client and back-end platforms. Mobile apps also introduce new issues for security and scalability.

WARNING: These slides contain lots of code.

We Will Discuss »


Why building mobile apps is different
A roundup of different client libraries and frameworks
Considerations for selecting mobile back-end platforms

Published in: Technology
1 Comment
8 Likes
Statistics
Notes
  • <br /><iframe width="350" height="288" src="http://www.youtube.com/embed/uI4d9DHMrvE" frameborder="0" allowfullscreen></iframe>
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total Views
6,540
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
120
Comments
1
Likes
8
Embeds 0
No embeds

No notes for slide
  • Creative Commons Attribution-Share Alike 3.0 United States License
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • Android &amp; iOS default response is a hash/dictionaryRuby on Rails
  • iOSFun factoid: the app store will reject your app if you don’t properly test your app using the reachability APIAndroidSearch around for Reachability - Connectivity Manager
  • If you provide and consume the api then auth is what u make it.Oauth 2 is a standard but not too heavyAbout 70% of the reason folks go to a special purpose built client library is auth, the second is object marshaling.The standard clients start to screw you over…Parameter signing are a nightmare for the app developer. RestKit
  • AndroidSUN JerseySpring MobileTradeoffs are around the App SizeForOauth: do the flow with the web browser but oauth 2 is a really pragmatic spec you can also pass a username and password. It will be up to the app. Client id and the client token. Get back an access token either in the header or as a param.
  • AndroidSUN JerseySpring MobileTradeoffs are around the App SizeForOauth: do the flow with the web browser but oauth 2 is a really pragmatic spec you can also pass a username and password. It will be up to the app. Client id and the client token. Get back an access token either in the header or as a param.
  • The Anatomy of Apps - How iPhone, Android & Facebook Apps Consume APIs

    1. 1. The Anatomy of AppsHow iPhone, Android & Facebook Apps Consume APIsEd Anuff@edanuffSam Ramji@sramjiBrian Mulloy@landlessness Apigee @apigee
    2. 2. groups.google.com/group/api-craft
    3. 3. youtube.com/apigee
    4. 4. New! IRC Channel #api-craft
    5. 5. App App App World of API Internal App APIUser Store Developer APIs Team Systems
    6. 6. Dogs API/dogs/ownersAuthorizationOAuth 2.0RESTful API Design - Second Editionhttp://www.youtube.com/watch?v=QpAhXa12xvU
    7. 7. Build an iPhone App, an Android App and aFacebook Web App**Ruby on Rails app hosted on Herokuhttp://devcenter.heroku.com/articles/facebook
    8. 8. App App App World of API Internal App APIUser Store Developer APIs Team Systems
    9. 9. Start with a basic HTTP request
    10. 10. AndroidHttpClient client = new DefaultHttpClient();HttpGet httpGet = new HttpGet("http://api.apizoo.com/v1/dogs");HttpResponse response = client.execute(httpGet);iOSNSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://api.apizoo.com/v1/dogs"]];NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];Ruby on Railsrequire net/httpresponse = Net::HTTP.get(‘api.apizoo.com/v1’, ‘/dogs’)
    11. 11. Parse the data
    12. 12. AndroidJSONObject dogs = new JSONObject(response);iOSimport "JSONKit.h"NSDictionary *dogs = [response objectFromData];Ruby on Railsrequire yajlparser = Yajl::Parser.newdogs = parser.parse(response) # returns a hash
    13. 13. Resource Object Mapping
    14. 14. RouteMapUse
    15. 15. Android Spring MobileRouterequestEntity = new HttpEntity<Object>(requestHeaders);ResponseEntity<Dog> responseEntity = restTemplate.exchange("http://api.apizoo.com/v1/dogs/15", HttpMethod.GET, requestEntity, Dog.class);
    16. 16. Android Spring MobileMap// Handled with introspection
    17. 17. Android Spring MobileUseDog dog = responseEntity.getBody()
    18. 18. iOS RestKitRoute#import <RestKit/RestKit.h>RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:@"http://api.apizoo.com/v1"];RKDynamicRouter* router = [[RKDynamicRouter new] autorelease];manager.router = router;[router routeClass:[Dog class] toResourcePath:@"/dogs" forMethod:RKRequestMethodPOST];[router routeClass:[Dog class] toResourcePath:@"/dogs/(dogID)"];
    19. 19. iOS RestKitMap@implementation Dog+ (NSDictionary*)elementToPropertyMappings { return [NSDictionary dictionaryWithKeysAndObjects: @"name", @"color", nil];}@end
    20. 20. iOS RestKitUseDog* dog = [Dog object];dog.name = @"Rover";Dog.color = @"red";[[RKObjectManager sharedManager] postObject:dog delegate:self];[[RKObjectManager sharedManager] deleteObject:dog delegate:self];
    21. 21. Ruby on Rails ActiveResourceRouteresource :dogs
    22. 22. Ruby on Rails ActiveResourceMapclass Dog < ActiveResource::Base self.site = "http://api.apizoo.com/v1"end
    23. 23. Ruby on Rails ActiveResourceUsedog = Dog.new name: ‘Rover’, color: ‘red’dog.savedog.destroy
    24. 24. Cache the response in a database
    25. 25. Android Jersey + JacksonUsageRoll your own
    26. 26. iOS RestKit + Core DataUsage#import <RestKit/CoreData/CoreData.h>RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:@"http://api.apizoo.com/v1"];manager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"DogApp.sqlite"];@implementation Dog + (NSString*)primaryKeyProperty { return @"dogID"; }@end
    27. 27. Ruby on Rails ActiveResource + ActiveRecordUsageclass DogResource < ActiveResource::Base self.site = http://api.apizoo.com/v1endclass Dog < ActiveRecord::Base # the before methods call DogResource methods before_create :create_resource before_update :update_resource before_destroy :destroy_resourceend
    28. 28. Simple to do list
    29. 29. Problem: we want new capabilities in our app notsupported by APIs.
    30. 30. Usergrid - Data & Querieshttp://www.youtube.com/watch?v=zLl56sU5Bt0
    31. 31. Androidusergrid_ sdkiOSUse RESTKitRuby on RailsProbably not applicable
    32. 32. What about offline cases
    33. 33. AndroidRoll your owniOS-(BOOL)reachable {Reachability *r = [Reachability reachabilityWithHostName:@"api.apizoo.com/v1"];NetworkStatus internetStatus = [r currentReachabilityStatus];if(internetStatus == NotReachable) { return NO;}return YES;}Ruby on RailsProbably not applicable
    34. 34. Get authorization out of the wayAssumption: the APIs we consume use OAuth 2
    35. 35. AndroidRoll your own
    36. 36. iOS RestKitRKObjectManager* objectManager = [RKObjectManager sharedManager];objectManager.client.baseURL = @”api.apizoo.com/v1";objectManager.client.OAuth2AccessToken = @"YOUR ACCESS TOKEN";objectManager.client.authenticationType = RKRequestAuthenticationTypeOAuth2;
    37. 37. Ruby on Rails Oauth Gem@consumer=OAuth::Consumer.new("key","secret", site: "api.apizoo.com/v1")@request_token=@consumer.get_request_tokensession[:request_token]=@request_tokenredirect_to @request_token.authorize_url@access_token=@request_token.get_access_token
    38. 38. AndroidBuilt-in JSON, etc.Spring Mobile (bundles Jersey & Jackson)iOSJSONKitRestKitCore DataRuby on RailsYAJLActiveResourceOauth
    39. 39. Coming Up: March Miniseries on Apps & APIs
    40. 40. Questions?
    41. 41. THANK YOUSubscribe to API webinars at:youtube.com/apigee
    42. 42. THANK YOUChat on IRC#api-craft
    43. 43. THANK YOUQuestions and ideas to:groups.google.com/group/api-craft
    44. 44. THANK YOUContact us at:@edanuffed@apigee.com@sramjisramji@apigee.com@landlessnessbrian@apigee.com
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×