SlideShare a Scribd company logo
by Peter Marks
http://petermarks.info
Restkit is a RESTful Object Mapping
  Framework for iOS and OSX.
Server - Client
Server - Client


Web Application
Server - Client


Web Application

   Database
Server - Client


  Web Application

     Database

RESTful JSON or XML
     webservice
Server - Client


  Web Application                       Obj C Application

     Database

RESTful JSON or XML
     webservice
Server - Client


  Web Application                       Obj C Application

     Database                             Object graph

RESTful JSON or XML
     webservice
Server - Client


  Web Application                       Obj C Application

     Database                             Object graph

RESTful JSON or XML
                                             Restkit
     webservice
Server - Client


  Web Application                       Obj C Application

     Database                             Object graph

RESTful JSON or XML
                                             Restkit
     webservice
Server - Client

                        GET Request
  Web Application                       Obj C Application

     Database                             Object graph

RESTful JSON or XML
                                             Restkit
     webservice
Server - Client

                        GET Request
  Web Application                       Obj C Application

     Database                             Object graph

RESTful JSON or XML
                                             Restkit
     webservice
Server - Client

                        GET Request
  Web Application                       Obj C Application

     Database                             Object graph
                        POST Request
RESTful JSON or XML
                                             Restkit
     webservice
Two representations of the same data:
Two representations of the same data:
/contacts
Two representations of the same data:
/contacts

[{




'contact':
{








'id':
1234,








'full_name':
'Peter
Marks',








'email':
'petertmarks@gmail.com',




}
},
{




'contact':
{








'id':
3456,








'full_name':
'Barack
Obama',








'email':
'barack94@aol.com',




}
}]
Two representations of the same data:
/contacts                                   @interface Contact : RKObject {
                                              NSNumber* _contactID;
                                              NSString* _fullName;
                                              NSString* _email;
[{                                          }




'contact':
{








'id':
1234,                         @property (retain) NSNumber* contactID;
                                            @property (retain) NSString* fullName;








'full_name':
'Peter
Marks',         @property (retain) NSString* email;








'email':
'petertmarks@gmail.com',   @end




}
},
{




'contact':
{








'id':
3456,








'full_name':
'Barack
Obama',








'email':
'barack94@aol.com',




}
}]
Two representations of the same data:
/contacts                                   @interface Contact : RKObject {
                                              NSNumber* _contactID;
                                              NSString* _fullName;
                                              NSString* _email;
[{                                          }




'contact':
{








'id':
1234,                         @property (retain) NSNumber* contactID;
                                            @property (retain) NSString* fullName;








'full_name':
'Peter
Marks',         @property (retain) NSString* email;








'email':
'petertmarks@gmail.com',   @end




}
},                                          @implementation Contact
                                            @synthesize ...;
{




'contact':
{                            + (NSDictionary*)elementToPropertyMappings {








'id':
3456,                           return [NSDictionary dictionaryWithKeysAndObjects:
                                                   @"id", @"contactID",








'full_name':
'Barack
Obama',               @"full_name", @"fullName",








'email':
'barack94@aol.com',               @"email", @"email",




}                                              nil];
}]                                          }

                                            @end
Fetch objects from server

- (void)applicationDidFinishLaunching:(UIApplication*)application withOptions:(NSDictionary*)options {
   RKClient* client = [RKClient clientWithBaseURL:@"http://restkit.org"];
}


- (void)loadContact {
   RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:@"http://restkit.org"];
   [manager loadObjectsAtResourcePath:@"/contacts/1" objectClass:[Contact class] delegate:self]
}


- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
   Contact* contact = [objects objectAtIndex:0];
   NSLog(@"Loaded Contact ID #%@ -> Name: %@, Company: %@",
             contact.id, contact.name, contact.company);
}
Set up routes

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   RKDynamicRouter* router = [RKDynamicRouter new];

    // Define a default resource path for all unspecified HTTP verbs
    [router routeClass:[Contact class] toResourcePath:@"/contacts/(contactID)"];
    [router routeClass:[Contact class] toResourcePath:@"/contacts" forMethod:RKRequestMethodPOST];

    [RKObjectManager sharedManager].router = router;
}
Post object to server

- (void) postObject {
   Contact * newContact = [[Contact alloc] init];
   newContact.fullName = @"Peter Marks";
   newContact.email = @"petertmarks@gmail.com";
   [[RKObjectManager sharedManager] postObject:newContact delegate:self];
}

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
   Contact* contact = [objects objectAtIndex:0];
   NSLog(@"Loaded Contact ID #%@ -> Name: %@, Company: %@",
       contact.contactID, contact.fullName, contact.company);
}
Core Data
Core Data
@interface Contact : RKManagedObject {}
@end

@implementation Contact
@synthesize ...;

+ (NSDictionary*)elementToPropertyMappings {
  return [NSDictionary dictionaryWithKeysAndObjects:
       @"id", @"contactID",
       @"full_name", @"fullName",
       @"email", @"email",
       nil];
}


+ (NSString*)primaryKeyProperty {
  return @"contactID";
}

@end
Relationship modeling
[{"project":
{




"id":
123,




"name":
"Produce
RestKit
Sample
Code",




"description":
"We
need
more
sample
code!",




"user":
{








"id":
1,








"name":
"Blake
Watters",








"email":
"blake@twotoasters.com"




},




"tasks":
[








{"id":
1,
"name":
"Identify
samples
to
write",
"assigned_user_id":
1},








{"id":
2,
"name":
"Write
the
code",
"assigned_user_id":
1},








{"id":
3,
"name":
"Push
to
Github",
"assigned_user_id":
1},








{"id":
4,
"name":
"Update
the
mailing
list",
"assigned_user_id":
1}




]
}},
Relationship mapping
Relationship mapping
@interface Project : RKManagedObject {
  NSNumber* _projectID;
  NSString* _name;
  NSString* _description;
  NSString* _userID;
  User* _user;
  NSArray* _tasks;
}

@property   (nonatomic,   retain)   NSNumber* projectID;
@property   (nonatomic,   retain)   NSString* name;
@property   (nonatomic,   retain)   NSString* description;
@property   (nonatomic,   retain)   NSString* userID;
@property   (nonatomic,   retain)   User* user;
@property   (nonatomic,   retain)   NSArray* tasks;

@end
Relationship mapping
@interface Project : RKManagedObject {
  NSNumber* _projectID;                                      @implementation Project
  NSString* _name;                                           @dynamic ...;
  NSString* _description;
  NSString* _userID;                                         + (NSDictionary*)elementToPropertyMappings {...}
  User* _user;
  NSArray* _tasks;                                           - (NSString*) primaryKeyProperty {
}                                                               return projectID;
                                                             }
@property   (nonatomic,   retain)   NSNumber* projectID;
@property   (nonatomic,   retain)   NSString* name;          + (NSDictionary*)elementToRelationshipMappings {
@property   (nonatomic,   retain)   NSString* description;     return [NSDictionary dictionaryWithKeysAndObjects:
@property   (nonatomic,   retain)   NSString* userID;               @"user", @"user",
@property   (nonatomic,   retain)   User* user;                     @"tasks", @"tasks",
@property   (nonatomic,   retain)   NSArray* tasks;                 nil];
                                                             }
@end
                                                             + (NSDictionary*)relationshipToPrimaryKeyPropertyMappings {
                                                               return [NSDictionary dictionaryWithObject:@"userID" forKey:@"user"];
                                                             }

                                                             @end
Relationship serialization

+ (NSArray*)relationshipsToSerialize {
  return [NSArray arrayWithObject:@"tasks"];
}



[{"project":
{




"id":
123,




"name":
"Produce
RestKit
Sample
Code",




"description":
"We
need
more
sample
code!",




"tasks":
[








{"id":
1,
"name":
"Identify
samples
to
write",
"assigned_user_id":
1},








{"id":
2,
"name":
"Write
the
code",
"assigned_user_id":
1},








{"id":
3,
"name":
"Push
to
Github",
"assigned_user_id":
1},








{"id":
4,
"name":
"Update
the
mailing
list",
"assigned_user_id":
1}




]
}},
Object mapping 2.0
Object mapping 2.0
Everything mentioned is for the current version of 0.9.2
Object mapping 2.0
Everything mentioned is for the current version of 0.9.2

Upcoming version 0.9.3 overhauls of Object mapping
Object mapping 2.0
Everything mentioned is for the current version of 0.9.2

Upcoming version 0.9.3 overhauls of Object mapping

Main difference is that mappings are no longer dependent
on class inheritance.
Object mapping 2.0
          Everything mentioned is for the current version of 0.9.2

          Upcoming version 0.9.3 overhauls of Object mapping

          Main difference is that mappings are no longer dependent
          on class inheritance.

// In this use-case Article is a vanilla NSObject with properties
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[Article class]];

// Add an attribute mapping to the object mapping directly
RKObjectAttributeMapping* titleMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"title"
                                                toKeyPath:@"title"];
[mapping addAttributeMapping:titleMapping];
Other cool stuff
RKRequestQueue
RKRequestQueue
- (void) postObject {
   Contact * newContact = [[Contact alloc] init];
   newContact.fullName = @"Peter Marks";
   newContact.email = @"petertmarks@gmail.com";
   [[RKObjectManager sharedManager] postObject:newContact delegate:self];
}

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
   Contact* contact = [objects objectAtIndex:0];
   NSLog(@"Loaded Contact ID #%@ -> Name: %@, Company: %@",
contact.contactID, contact.fullName, contact.company);
}
RKRequestQueue
- (void) postObject {
   Contact * newContact = [[Contact alloc] init];
   newContact.fullName = @"Peter Marks";
   newContact.email = @"petertmarks@gmail.com";
   [[RKObjectManager sharedManager] postObject:newContact delegate:self];
}

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
   Contact* contact = [objects objectAtIndex:0];
   NSLog(@"Loaded Contact ID #%@ -> Name: %@, Company: %@",
contact.contactID, contact.fullName, contact.company);
}

// We have been obscured -- cancel any pending requests
- (void)viewWillDisappear:(BOOL)animated {
   [[RKRequestQueue sharedQueue] cancelRequestsWithDelegate:self];
}
Background requests

- (void)backgroundUpload {
   RKRequest* request = [[RKClient sharedClient] post:@"somewhere" delegate:self];
   request.backgroundPolicy = RKRequestBackgroundPolicyNone; // Take no action with regard to backgrounding
   request.backgroundPolicy = RKRequestBackgroundPolicyCancel; // If the app switches to the background, cancel the request
   request.backgroundPolicy = RKRequestBackgroundPolicyContinue; // Continue the request in the background
   request.backgroundPolicy = RKRequestBackgroundPolicyRequeue; // Cancel the request and place it back on the queue for next
activation
}
Multi-part requests

// Create an Attachment
RKParamsAttachment* attachment = [params setFile:myFilePath forParam:@"image1"];
attachment.MIMEType = @"image/gif";
attachment.fileName = @"picture.gif";

// Attach an Image from the App Bundle
UIImage* image = [UIImage imageNamed:@"another_image.png"];
NSData* imageData = UIImagePNGRepresentation(image);
[params setData:imageData MIMEType:@"image/png" forParam:@"image2"];

// Send a Request!
[[RKClient sharedClient] post:@"/uploadImages" params:params delegate:self];
Database seeding

RKManagedObjectSeeder* seeder = [RKManagedObjectSeeder objectSeederWithObjectManager:
                              [RKObjectManager sharedManager]];

// Seed the database with User objects. The class will be inferred via element registration
[seeder seedObjectsFromFiles:@"users.json", nil];
Integration Layers

Ruby on Rails
RKRailsRouter – A Router implementation aware of Ruby on Rails idioms


Three20
RKRequestTTModel – An implementation of the TTModel protocol for
Three20 that allows RestKit object loaders to drive Three20 tables
More information


• http://Restkit.org

• http://github.com/twotoasters/RestKit/

• http://groups.google.com/group/restkit
Canned discussion prompt:
How do others solve this problem?
Ad

More Related Content

What's hot (19)

Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
MongoDB
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQL
MongoDB
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
Norberto Leite
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
Eliot Horowitz
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
Tobias Trelle
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
MongoDB
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
MongoDB
 
2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky
Data Con LA
 
MongoDB crud
MongoDB crudMongoDB crud
MongoDB crud
Darshan Jayarama
 
Database Trends for Modern Applications: Why the Database You Choose Matters
Database Trends for Modern Applications: Why the Database You Choose Matters Database Trends for Modern Applications: Why the Database You Choose Matters
Database Trends for Modern Applications: Why the Database You Choose Matters
MongoDB
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live Hacking
Tobias Trelle
 
Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Spring Data, Jongo & Co.
Spring Data, Jongo & Co.
Tobias Trelle
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
Trisha Gee
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
MongoDB
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDB
James Williams
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
MongoDB
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
MongoDB
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDB
Uwe Printz
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
MongoDB
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQL
MongoDB
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
Norberto Leite
 
MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010MongoDB Java Development - MongoBoston 2010
MongoDB Java Development - MongoBoston 2010
Eliot Horowitz
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
Tobias Trelle
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
MongoDB
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
MongoDB
 
2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky2014 bigdatacamp asya_kamsky
2014 bigdatacamp asya_kamsky
Data Con LA
 
Database Trends for Modern Applications: Why the Database You Choose Matters
Database Trends for Modern Applications: Why the Database You Choose Matters Database Trends for Modern Applications: Why the Database You Choose Matters
Database Trends for Modern Applications: Why the Database You Choose Matters
MongoDB
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live Hacking
Tobias Trelle
 
Spring Data, Jongo & Co.
Spring Data, Jongo & Co.Spring Data, Jongo & Co.
Spring Data, Jongo & Co.
Tobias Trelle
 
What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?What do you mean, Backwards Compatibility?
What do you mean, Backwards Compatibility?
Trisha Gee
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You ScaleIndexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
MongoDB
 
Java development with MongoDB
Java development with MongoDBJava development with MongoDB
Java development with MongoDB
James Williams
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
Benefits of Using MongoDB Over RDBMS (At An Evening with MongoDB Minneapolis ...
MongoDB
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
MongoDB
 
Map/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDBMap/Confused? A practical approach to Map/Reduce with MongoDB
Map/Confused? A practical approach to Map/Reduce with MongoDB
Uwe Printz
 

Similar to Introduction to Restkit (20)

RESTfull with RestKit
RESTfull with RestKitRESTfull with RestKit
RESTfull with RestKit
Taras Kalapun
 
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
ITGinGer
 
Json
JsonJson
Json
Raphael Wanjiku
 
RESTful JSON web databases
RESTful JSON web databasesRESTful JSON web databases
RESTful JSON web databases
kriszyp
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
Oliver Gierke
 
Spring data
Spring dataSpring data
Spring data
명철 강
 
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
apidays
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learnedGraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
Drupal Mobile
Drupal MobileDrupal Mobile
Drupal Mobile
Ruben Teijeiro
 
[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)
croquiscom
 
Elasticsearch for SQL Users
Elasticsearch for SQL UsersElasticsearch for SQL Users
Elasticsearch for SQL Users
All Things Open
 
GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learned
MarcinStachniuk
 
Launching Beeline with Firebase
Launching Beeline with FirebaseLaunching Beeline with Firebase
Launching Beeline with Firebase
Chetan Padia
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revised
MongoDB
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational Awareness
MongoDB
 
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScriptMongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
MongoDB
 
Requery overview
Requery overviewRequery overview
Requery overview
Sunghyouk Bae
 
Application development with Oracle NoSQL Database 3.0
Application development with Oracle NoSQL Database 3.0Application development with Oracle NoSQL Database 3.0
Application development with Oracle NoSQL Database 3.0
Anuj Sahni
 
Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2
kriszyp
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
Oliver Gierke
 
RESTfull with RestKit
RESTfull with RestKitRESTfull with RestKit
RESTfull with RestKit
Taras Kalapun
 
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
MPD2011 | Сергей Клюев "RESTfull iOS with RestKit"
ITGinGer
 
RESTful JSON web databases
RESTful JSON web databasesRESTful JSON web databases
RESTful JSON web databases
kriszyp
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
Oliver Gierke
 
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
APIdays Paris 2018 - Building scalable, type-safe GraphQL servers from scratc...
apidays
 
GraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learnedGraphQL - when REST API is to less - lessons learned
GraphQL - when REST API is to less - lessons learned
MarcinStachniuk
 
[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)
croquiscom
 
Elasticsearch for SQL Users
Elasticsearch for SQL UsersElasticsearch for SQL Users
Elasticsearch for SQL Users
All Things Open
 
GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learned
MarcinStachniuk
 
Launching Beeline with Firebase
Launching Beeline with FirebaseLaunching Beeline with Firebase
Launching Beeline with Firebase
Chetan Padia
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revised
MongoDB
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational Awareness
MongoDB
 
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScriptMongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
MongoDB World 2019: Building a GraphQL API with MongoDB, Prisma, & TypeScript
MongoDB
 
Application development with Oracle NoSQL Database 3.0
Application development with Oracle NoSQL Database 3.0Application development with Oracle NoSQL Database 3.0
Application development with Oracle NoSQL Database 3.0
Anuj Sahni
 
Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2
kriszyp
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
Oliver Gierke
 
Ad

Recently uploaded (20)

Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
IEDM 2024 Tutorial2_Advances in CMOS Technologies and Future Directions for C...
organizerofv
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Heap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and DeletionHeap, Types of Heap, Insertion and Deletion
Heap, Types of Heap, Insertion and Deletion
Jaydeep Kale
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded DevelopersLinux Support for SMARC: How Toradex Empowers Embedded Developers
Linux Support for SMARC: How Toradex Empowers Embedded Developers
Toradex
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager APIUiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPath Community Berlin: Orchestrator API, Swagger, and Test Manager API
UiPathCommunity
 
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven InsightsAndrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell: Transforming Business Strategy Through Data-Driven Insights
Andrew Marnell
 
Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025Splunk Security Update | Public Sector Summit Germany 2025
Splunk Security Update | Public Sector Summit Germany 2025
Splunk
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdfThe Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
The Evolution of Meme Coins A New Era for Digital Currency ppt.pdf
Abi john
 
Ad

Introduction to Restkit

  • 2. Restkit is a RESTful Object Mapping Framework for iOS and OSX.
  • 4. Server - Client Web Application
  • 5. Server - Client Web Application Database
  • 6. Server - Client Web Application Database RESTful JSON or XML webservice
  • 7. Server - Client Web Application Obj C Application Database RESTful JSON or XML webservice
  • 8. Server - Client Web Application Obj C Application Database Object graph RESTful JSON or XML webservice
  • 9. Server - Client Web Application Obj C Application Database Object graph RESTful JSON or XML Restkit webservice
  • 10. Server - Client Web Application Obj C Application Database Object graph RESTful JSON or XML Restkit webservice
  • 11. Server - Client GET Request Web Application Obj C Application Database Object graph RESTful JSON or XML Restkit webservice
  • 12. Server - Client GET Request Web Application Obj C Application Database Object graph RESTful JSON or XML Restkit webservice
  • 13. Server - Client GET Request Web Application Obj C Application Database Object graph POST Request RESTful JSON or XML Restkit webservice
  • 14. Two representations of the same data:
  • 15. Two representations of the same data: /contacts
  • 16. Two representations of the same data: /contacts [{ 



'contact':
{ 







'id':
1234, 







'full_name':
'Peter
Marks', 







'email':
'[email protected]', 



} }, { 



'contact':
{ 







'id':
3456, 







'full_name':
'Barack
Obama', 







'email':
'[email protected]', 



} }]
  • 17. Two representations of the same data: /contacts @interface Contact : RKObject { NSNumber* _contactID; NSString* _fullName; NSString* _email; [{ } 



'contact':
{ 







'id':
1234, @property (retain) NSNumber* contactID; @property (retain) NSString* fullName; 







'full_name':
'Peter
Marks', @property (retain) NSString* email; 







'email':
'[email protected]', @end 



} }, { 



'contact':
{ 







'id':
3456, 







'full_name':
'Barack
Obama', 







'email':
'[email protected]', 



} }]
  • 18. Two representations of the same data: /contacts @interface Contact : RKObject { NSNumber* _contactID; NSString* _fullName; NSString* _email; [{ } 



'contact':
{ 







'id':
1234, @property (retain) NSNumber* contactID; @property (retain) NSString* fullName; 







'full_name':
'Peter
Marks', @property (retain) NSString* email; 







'email':
'[email protected]', @end 



} }, @implementation Contact @synthesize ...; { 



'contact':
{ + (NSDictionary*)elementToPropertyMappings { 







'id':
3456, return [NSDictionary dictionaryWithKeysAndObjects: @"id", @"contactID", 







'full_name':
'Barack
Obama', @"full_name", @"fullName", 







'email':
'[email protected]', @"email", @"email", 



} nil]; }] } @end
  • 19. Fetch objects from server - (void)applicationDidFinishLaunching:(UIApplication*)application withOptions:(NSDictionary*)options { RKClient* client = [RKClient clientWithBaseURL:@"http://restkit.org"]; } - (void)loadContact { RKObjectManager* manager = [RKObjectManager objectManagerWithBaseURL:@"http://restkit.org"]; [manager loadObjectsAtResourcePath:@"/contacts/1" objectClass:[Contact class] delegate:self] } - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects { Contact* contact = [objects objectAtIndex:0]; NSLog(@"Loaded Contact ID #%@ -> Name: %@, Company: %@", contact.id, contact.name, contact.company); }
  • 20. Set up routes - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { RKDynamicRouter* router = [RKDynamicRouter new]; // Define a default resource path for all unspecified HTTP verbs [router routeClass:[Contact class] toResourcePath:@"/contacts/(contactID)"]; [router routeClass:[Contact class] toResourcePath:@"/contacts" forMethod:RKRequestMethodPOST]; [RKObjectManager sharedManager].router = router; }
  • 21. Post object to server - (void) postObject { Contact * newContact = [[Contact alloc] init]; newContact.fullName = @"Peter Marks"; newContact.email = @"[email protected]"; [[RKObjectManager sharedManager] postObject:newContact delegate:self]; } - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects { Contact* contact = [objects objectAtIndex:0]; NSLog(@"Loaded Contact ID #%@ -> Name: %@, Company: %@", contact.contactID, contact.fullName, contact.company); }
  • 23. Core Data @interface Contact : RKManagedObject {} @end @implementation Contact @synthesize ...; + (NSDictionary*)elementToPropertyMappings { return [NSDictionary dictionaryWithKeysAndObjects: @"id", @"contactID", @"full_name", @"fullName", @"email", @"email", nil]; } + (NSString*)primaryKeyProperty { return @"contactID"; } @end
  • 24. Relationship modeling [{"project":
{ 



"id":
123, 



"name":
"Produce
RestKit
Sample
Code", 



"description":
"We
need
more
sample
code!", 



"user":
{ 







"id":
1, 







"name":
"Blake
Watters", 







"email":
"[email protected]" 



}, 



"tasks":
[ 







{"id":
1,
"name":
"Identify
samples
to
write",
"assigned_user_id":
1}, 







{"id":
2,
"name":
"Write
the
code",
"assigned_user_id":
1}, 







{"id":
3,
"name":
"Push
to
Github",
"assigned_user_id":
1}, 







{"id":
4,
"name":
"Update
the
mailing
list",
"assigned_user_id":
1} 



] }},
  • 26. Relationship mapping @interface Project : RKManagedObject { NSNumber* _projectID; NSString* _name; NSString* _description; NSString* _userID; User* _user; NSArray* _tasks; } @property (nonatomic, retain) NSNumber* projectID; @property (nonatomic, retain) NSString* name; @property (nonatomic, retain) NSString* description; @property (nonatomic, retain) NSString* userID; @property (nonatomic, retain) User* user; @property (nonatomic, retain) NSArray* tasks; @end
  • 27. Relationship mapping @interface Project : RKManagedObject { NSNumber* _projectID; @implementation Project NSString* _name; @dynamic ...; NSString* _description; NSString* _userID; + (NSDictionary*)elementToPropertyMappings {...} User* _user; NSArray* _tasks; - (NSString*) primaryKeyProperty { } return projectID; } @property (nonatomic, retain) NSNumber* projectID; @property (nonatomic, retain) NSString* name; + (NSDictionary*)elementToRelationshipMappings { @property (nonatomic, retain) NSString* description; return [NSDictionary dictionaryWithKeysAndObjects: @property (nonatomic, retain) NSString* userID; @"user", @"user", @property (nonatomic, retain) User* user; @"tasks", @"tasks", @property (nonatomic, retain) NSArray* tasks; nil]; } @end + (NSDictionary*)relationshipToPrimaryKeyPropertyMappings { return [NSDictionary dictionaryWithObject:@"userID" forKey:@"user"]; } @end
  • 28. Relationship serialization + (NSArray*)relationshipsToSerialize { return [NSArray arrayWithObject:@"tasks"]; } [{"project":
{ 



"id":
123, 



"name":
"Produce
RestKit
Sample
Code", 



"description":
"We
need
more
sample
code!", 



"tasks":
[ 







{"id":
1,
"name":
"Identify
samples
to
write",
"assigned_user_id":
1}, 







{"id":
2,
"name":
"Write
the
code",
"assigned_user_id":
1}, 







{"id":
3,
"name":
"Push
to
Github",
"assigned_user_id":
1}, 







{"id":
4,
"name":
"Update
the
mailing
list",
"assigned_user_id":
1} 



] }},
  • 30. Object mapping 2.0 Everything mentioned is for the current version of 0.9.2
  • 31. Object mapping 2.0 Everything mentioned is for the current version of 0.9.2 Upcoming version 0.9.3 overhauls of Object mapping
  • 32. Object mapping 2.0 Everything mentioned is for the current version of 0.9.2 Upcoming version 0.9.3 overhauls of Object mapping Main difference is that mappings are no longer dependent on class inheritance.
  • 33. Object mapping 2.0 Everything mentioned is for the current version of 0.9.2 Upcoming version 0.9.3 overhauls of Object mapping Main difference is that mappings are no longer dependent on class inheritance. // In this use-case Article is a vanilla NSObject with properties RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[Article class]]; // Add an attribute mapping to the object mapping directly RKObjectAttributeMapping* titleMapping = [RKObjectAttributeMapping mappingFromKeyPath:@"title" toKeyPath:@"title"]; [mapping addAttributeMapping:titleMapping];
  • 36. RKRequestQueue - (void) postObject { Contact * newContact = [[Contact alloc] init]; newContact.fullName = @"Peter Marks"; newContact.email = @"[email protected]"; [[RKObjectManager sharedManager] postObject:newContact delegate:self]; } - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects { Contact* contact = [objects objectAtIndex:0]; NSLog(@"Loaded Contact ID #%@ -> Name: %@, Company: %@", contact.contactID, contact.fullName, contact.company); }
  • 37. RKRequestQueue - (void) postObject { Contact * newContact = [[Contact alloc] init]; newContact.fullName = @"Peter Marks"; newContact.email = @"[email protected]"; [[RKObjectManager sharedManager] postObject:newContact delegate:self]; } - (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects { Contact* contact = [objects objectAtIndex:0]; NSLog(@"Loaded Contact ID #%@ -> Name: %@, Company: %@", contact.contactID, contact.fullName, contact.company); } // We have been obscured -- cancel any pending requests - (void)viewWillDisappear:(BOOL)animated { [[RKRequestQueue sharedQueue] cancelRequestsWithDelegate:self]; }
  • 38. Background requests - (void)backgroundUpload { RKRequest* request = [[RKClient sharedClient] post:@"somewhere" delegate:self]; request.backgroundPolicy = RKRequestBackgroundPolicyNone; // Take no action with regard to backgrounding request.backgroundPolicy = RKRequestBackgroundPolicyCancel; // If the app switches to the background, cancel the request request.backgroundPolicy = RKRequestBackgroundPolicyContinue; // Continue the request in the background request.backgroundPolicy = RKRequestBackgroundPolicyRequeue; // Cancel the request and place it back on the queue for next activation }
  • 39. Multi-part requests // Create an Attachment RKParamsAttachment* attachment = [params setFile:myFilePath forParam:@"image1"]; attachment.MIMEType = @"image/gif"; attachment.fileName = @"picture.gif"; // Attach an Image from the App Bundle UIImage* image = [UIImage imageNamed:@"another_image.png"]; NSData* imageData = UIImagePNGRepresentation(image); [params setData:imageData MIMEType:@"image/png" forParam:@"image2"]; // Send a Request! [[RKClient sharedClient] post:@"/uploadImages" params:params delegate:self];
  • 40. Database seeding RKManagedObjectSeeder* seeder = [RKManagedObjectSeeder objectSeederWithObjectManager: [RKObjectManager sharedManager]]; // Seed the database with User objects. The class will be inferred via element registration [seeder seedObjectsFromFiles:@"users.json", nil];
  • 41. Integration Layers Ruby on Rails RKRailsRouter – A Router implementation aware of Ruby on Rails idioms Three20 RKRequestTTModel – An implementation of the TTModel protocol for Three20 that allows RestKit object loaders to drive Three20 tables
  • 42. More information • http://Restkit.org • http://github.com/twotoasters/RestKit/ • http://groups.google.com/group/restkit
  • 43. Canned discussion prompt: How do others solve this problem?

Editor's Notes

  • #2: Hey, I’m Peter. I’m a Cocoa and Ruby programmer and am here to talk about a tool I use called Restkit to bridge those two worlds. \n
  • #3: \n
  • #4: It aims to simplify communication between server and client. On one side you’ve got a server, it’s running a web app managing data in a database, it’s using a restful json or XML webservice to communicate with other programs. On the other side you have an iOS or OSX device running a native objective c application. It’s managing data in an object graph, maybe using core data. It can use Restkit to easily exchange data with the server via GET, POST, PUT and DELETE requests. \n
  • #5: It aims to simplify communication between server and client. On one side you’ve got a server, it’s running a web app managing data in a database, it’s using a restful json or XML webservice to communicate with other programs. On the other side you have an iOS or OSX device running a native objective c application. It’s managing data in an object graph, maybe using core data. It can use Restkit to easily exchange data with the server via GET, POST, PUT and DELETE requests. \n
  • #6: It aims to simplify communication between server and client. On one side you’ve got a server, it’s running a web app managing data in a database, it’s using a restful json or XML webservice to communicate with other programs. On the other side you have an iOS or OSX device running a native objective c application. It’s managing data in an object graph, maybe using core data. It can use Restkit to easily exchange data with the server via GET, POST, PUT and DELETE requests. \n
  • #7: It aims to simplify communication between server and client. On one side you’ve got a server, it’s running a web app managing data in a database, it’s using a restful json or XML webservice to communicate with other programs. On the other side you have an iOS or OSX device running a native objective c application. It’s managing data in an object graph, maybe using core data. It can use Restkit to easily exchange data with the server via GET, POST, PUT and DELETE requests. \n
  • #8: It aims to simplify communication between server and client. On one side you’ve got a server, it’s running a web app managing data in a database, it’s using a restful json or XML webservice to communicate with other programs. On the other side you have an iOS or OSX device running a native objective c application. It’s managing data in an object graph, maybe using core data. It can use Restkit to easily exchange data with the server via GET, POST, PUT and DELETE requests. \n
  • #9: It aims to simplify communication between server and client. On one side you’ve got a server, it’s running a web app managing data in a database, it’s using a restful json or XML webservice to communicate with other programs. On the other side you have an iOS or OSX device running a native objective c application. It’s managing data in an object graph, maybe using core data. It can use Restkit to easily exchange data with the server via GET, POST, PUT and DELETE requests. \n
  • #10: It aims to simplify communication between server and client. On one side you’ve got a server, it’s running a web app managing data in a database, it’s using a restful json or XML webservice to communicate with other programs. On the other side you have an iOS or OSX device running a native objective c application. It’s managing data in an object graph, maybe using core data. It can use Restkit to easily exchange data with the server via GET, POST, PUT and DELETE requests. \n
  • #11: It aims to simplify communication between server and client. On one side you’ve got a server, it’s running a web app managing data in a database, it’s using a restful json or XML webservice to communicate with other programs. On the other side you have an iOS or OSX device running a native objective c application. It’s managing data in an object graph, maybe using core data. It can use Restkit to easily exchange data with the server via GET, POST, PUT and DELETE requests. \n
  • #12: It aims to simplify communication between server and client. On one side you’ve got a server, it’s running a web app managing data in a database, it’s using a restful json or XML webservice to communicate with other programs. On the other side you have an iOS or OSX device running a native objective c application. It’s managing data in an object graph, maybe using core data. It can use Restkit to easily exchange data with the server via GET, POST, PUT and DELETE requests. \n
  • #13: It aims to simplify communication between server and client. On one side you’ve got a server, it’s running a web app managing data in a database, it’s using a restful json or XML webservice to communicate with other programs. On the other side you have an iOS or OSX device running a native objective c application. It’s managing data in an object graph, maybe using core data. It can use Restkit to easily exchange data with the server via GET, POST, PUT and DELETE requests. \n
  • #14: The first problem Restkit makes easier is translating different representations of the same data. You have a web service json response that lists objects using its own attribute names. In this example they’re in underscore case. Then you’ve got your Objective C model with attributes that are semantically the same, they’re just in camel case. Restkit bridges the gap with Object mapping. Restkit models provide a rosetta stone-like method that translates server attribute names to its own attribute names. This makes representing and interacting with remote objects a lot easier. \n
  • #15: The first problem Restkit makes easier is translating different representations of the same data. You have a web service json response that lists objects using its own attribute names. In this example they’re in underscore case. Then you’ve got your Objective C model with attributes that are semantically the same, they’re just in camel case. Restkit bridges the gap with Object mapping. Restkit models provide a rosetta stone-like method that translates server attribute names to its own attribute names. This makes representing and interacting with remote objects a lot easier. \n
  • #16: The first problem Restkit makes easier is translating different representations of the same data. You have a web service json response that lists objects using its own attribute names. In this example they’re in underscore case. Then you’ve got your Objective C model with attributes that are semantically the same, they’re just in camel case. Restkit bridges the gap with Object mapping. Restkit models provide a rosetta stone-like method that translates server attribute names to its own attribute names. This makes representing and interacting with remote objects a lot easier. \n
  • #17: The first problem Restkit makes easier is translating different representations of the same data. You have a web service json response that lists objects using its own attribute names. In this example they’re in underscore case. Then you’ve got your Objective C model with attributes that are semantically the same, they’re just in camel case. Restkit bridges the gap with Object mapping. Restkit models provide a rosetta stone-like method that translates server attribute names to its own attribute names. This makes representing and interacting with remote objects a lot easier. \n
  • #18: First we set up a RKClient with a base url of the web service it will be interacting with. Next, we instruct our client to send a GET request to a specific path. We set our class as the delegate and the request is sent asynchronously. When a response is received, Restkit’s object mapper uses the mappings we defined to parse the JSON or XML response body into Objective C objects. These objects are then sent to our delegate’s objectLoaderDidLoadObjects method where you can handle them by rendering to screen or whatever else. \n
  • #19: Restkit also provides a routing system that keeps your code DRY. In that first example we had to provide the route for the resource. In REST, resources generally have the same path and it’s just the HTTP method that changes for each action. To avoid repeating resource names, we set up routes for our object manager.\n
  • #20: Now that we’ve got our routes set up, we can use the RKObjectManager’s postObject method to create a new object on our remote web service. Again, we get a response back in the objectLoaderDidLoadObjects method. \n
  • #21: Restkit’s object mappings provides support for Core Data managed objects as well. To do so, you must designate a primaryKeyProperty that’s semantically unique for that object. This will almost always be the server’s auto incremented database ID. Restkit uses this primary key to make sure it knows if it fetches the same object twice.\n
  • #22: Where this core data integration really comes in handy is the mapping of relationships. Say this is a remote representation of data that corresponds to a “Project” entity in your client’s core data datamodel. It has a one to one relationship with another entity called “User” and a one to many relationship with an entity called Task”. Restkit can use it’s relationship mapping to convert the nested objects in this resource into multiple Objective C entities with relationships intact. \n
  • #23: So here’s our interface. It’s a standard core data setup, only difference is that it inherits from RKManagedObject, which itself inherits from NSManaged Object. In our implementation, we provide an elementsToPropertyMappings dictionary and a primaryKeyProperty like we have previously. The first new thing is this elementsToRelationshipMappings relationship, which instructs the mapper to look for associated objects nested as a sub-dictionary in a JSON payload. The second new thing is the relationshipToPrimaryKeyPropertyMappings method. This instructs the mapper to connect a Core Data relationship by using the value stored in another property to lookup the target object. \n
  • #24: So here’s our interface. It’s a standard core data setup, only difference is that it inherits from RKManagedObject, which itself inherits from NSManaged Object. In our implementation, we provide an elementsToPropertyMappings dictionary and a primaryKeyProperty like we have previously. The first new thing is this elementsToRelationshipMappings relationship, which instructs the mapper to look for associated objects nested as a sub-dictionary in a JSON payload. The second new thing is the relationshipToPrimaryKeyPropertyMappings method. This instructs the mapper to connect a Core Data relationship by using the value stored in another property to lookup the target object. \n
  • #25: In addition to receiving entire object graphs from remote resources, we can also create entire object graphs on remote resources through relationship serialization This is actually a pet feature that I ended up implementing out of my need to POST an object with 50 to 100 children. Being able to post an object with its relationships dramatically cuts down the number of requests I need to send. \n
  • #26: It’s worth mentioning that Restkit’s object mapping system is about to change. Everything I’ve mentioned is for the current version of 0.9.2. The upcoming version of 0.9.3 overhauls object mapping architecture. The main difference is that mappings are no longer dependent on class inheritance. This makes the mapping system a lot more flexible and light weight. All the functionality I’ve discussed will remain intact and built upon. \n\nI’d usually be concerned with such a major overhaul in architecture, but I’m reassured by the patient approach the team is taking to release this version as well the suite of unit and integration tests to measure the new version against. I know it’s probably a bad practice to present two versions of the API and I hope this doesn’t confuse people too much. I just wanted to give anyone who might implement Restkit in their project a month or so from now a heads up for what’s to come. \n
  • #27: It’s worth mentioning that Restkit’s object mapping system is about to change. Everything I’ve mentioned is for the current version of 0.9.2. The upcoming version of 0.9.3 overhauls object mapping architecture. The main difference is that mappings are no longer dependent on class inheritance. This makes the mapping system a lot more flexible and light weight. All the functionality I’ve discussed will remain intact and built upon. \n\nI’d usually be concerned with such a major overhaul in architecture, but I’m reassured by the patient approach the team is taking to release this version as well the suite of unit and integration tests to measure the new version against. I know it’s probably a bad practice to present two versions of the API and I hope this doesn’t confuse people too much. I just wanted to give anyone who might implement Restkit in their project a month or so from now a heads up for what’s to come. \n
  • #28: It’s worth mentioning that Restkit’s object mapping system is about to change. Everything I’ve mentioned is for the current version of 0.9.2. The upcoming version of 0.9.3 overhauls object mapping architecture. The main difference is that mappings are no longer dependent on class inheritance. This makes the mapping system a lot more flexible and light weight. All the functionality I’ve discussed will remain intact and built upon. \n\nI’d usually be concerned with such a major overhaul in architecture, but I’m reassured by the patient approach the team is taking to release this version as well the suite of unit and integration tests to measure the new version against. I know it’s probably a bad practice to present two versions of the API and I hope this doesn’t confuse people too much. I just wanted to give anyone who might implement Restkit in their project a month or so from now a heads up for what’s to come. \n
  • #29: It’s worth mentioning that Restkit’s object mapping system is about to change. Everything I’ve mentioned is for the current version of 0.9.2. The upcoming version of 0.9.3 overhauls object mapping architecture. The main difference is that mappings are no longer dependent on class inheritance. This makes the mapping system a lot more flexible and light weight. All the functionality I’ve discussed will remain intact and built upon. \n\nI’d usually be concerned with such a major overhaul in architecture, but I’m reassured by the patient approach the team is taking to release this version as well the suite of unit and integration tests to measure the new version against. I know it’s probably a bad practice to present two versions of the API and I hope this doesn’t confuse people too much. I just wanted to give anyone who might implement Restkit in their project a month or so from now a heads up for what’s to come. \n
  • #30: Up to this point I’ve discussed Restkit’s object mapping system, which I see as its most unique and powerful feature. Restkit also has some other cool features to smooth the process between client and server data exchange.\n
  • #31: So looking back at the previous code we looked at to post and object and receive its response via an asynchronous callback. What’s going on quietly behind the scenes here is a class called RKRequestQueue. RKRequestQueue has three primary responsibilities: managing request memory, ensuring the network does not get overly burdened, and managing request life cycle. It enables us to post objects and recieve responses without worrying about retaining anything. It also lets us cancel requests that no longer need to be made, usually because of user action. \n
  • #32: So looking back at the previous code we looked at to post and object and receive its response via an asynchronous callback. What’s going on quietly behind the scenes here is a class called RKRequestQueue. RKRequestQueue has three primary responsibilities: managing request memory, ensuring the network does not get overly burdened, and managing request life cycle. It enables us to post objects and recieve responses without worrying about retaining anything. It also lets us cancel requests that no longer need to be made, usually because of user action. \n
  • #33: setting a backgroundPolicy on a request will allow the application to consume resources necessary to send and handle requests. \n
  • #34: Restkit includes a simple interface for building multi-part requests to include things like file attachments. \n
  • #35: You may want to ship your application to the App Store with content already available in the local store. Restkit includes a simple object seeding implementation for this purpose via the RKObjectSeeder class. It will take a JSON file you ship with your app and read it into objects just as it would a remote resource. \n
  • #36: \n
  • #37: \n
  • #38: \n