Book Image

RestKit for iOS

By : Taras Kalapun
Book Image

RestKit for iOS

By: Taras Kalapun

Overview of this book

<p>RestKit is an iOS framework for streamlining communication with web services, and it relies on the AFNetworking library that is used by thousands of app developers. It has an interface that is elegant and well designed, and it provides a powerful object-mapping engine that integrates well with the CoreData database. RestKit for iOS will teach you everything from loading a simple list of objects to creating a fully-featured app.<br /><br />RestKit for iOS delivers constructive tools and insights into app development that will benefit any app developer. The book starts with a simple example and then moves on to more complex ones as your knowledge increases. By the end of the guide, you will be able to build a fully-featured app that uses RESTful web services and performs CRUD object manipulation.<br /><br />RestKit for iOS will provide you with all the information you need to boost the development process of both simple and complex apps. Once you have executed a simple example and reviewed the basic theory, you will move on to more advanced concepts with descriptions of real-life scenarios and how to overcome bottlenecks. RestKit for iOS is full of real-life examples that show you how to simplify data loading, basic and advanced object mapping, metadata mapping, and routing. This book also teaches you about routing, RESTful object manipulation and synchronization, integration with the user interface, and caching</p>
Table of Contents (13 chapters)

How it works?


We can describe how you interact with RestKit by looking at the following sample sequence diagram for getting data:

RestKit usage sequence diagram

When you, as a Caller, wish to get data from a Remote web service, you ask for it on RestKit. It then decides on a strategy and gets the paths and mapping information by checking a configuration for the particular type of objects that you want. RestKit uses AFNetworking under the hood to do the actual data retrieving from the Remote and parsing in to NSDictionary or NSArray. AFNetworking itself checks with NSURLCache if it should make a request again, or use the cache. (We'll discuss this in detail in Chapter 4, Advanced Stuff in the HTTP Caching section). AFNetworking then gives back the response to a RestKit, along with all additional information, which were gathered during the "request-response-parse sequence".

If you're not using Core Data for this type of objects (we can call it "In-Memory object"), RestKit creates new instances of the object, and maps a response data to it. It then returns the object(s) back to the Caller.

Now if you are using Core Data, and the object is a Managed object, RestKit will first check with the Core Data if it already has an object with a similar ID. It will also check if the object in response has a deleted flag. It will then do the mapping and update/delete the particular object, and check how to deal with orphan objects. At the end, it will return the resultant objects to the user. Core Data itself will notify all its observers via Key Value Observing (KVO) about the changes.