Skip to content

Commit

Permalink
Merge pull request #12 from MichaelDooHickey/patch-1
Browse files Browse the repository at this point in the history
responseDescriptorWithMapping deprecated method replacement
  • Loading branch information
blakewatters committed Sep 6, 2013
2 parents 588f967 + d7355b8 commit 90e29af
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,14 +521,15 @@ This illustrates an important point about `RKObjectMapping` (and through inherit
After creating the entity mapping for the `Gist` entity, the next block of code establishes a binding between an HTTP response and the mapping:

```objc
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping pathPattern:@"/gists/public" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:entityMapping method:RKRequestMethodAny pathPattern:@"/gists/public" keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
```
Here we are introduced to the [`RKResponseDescriptor`](http:https://restkit.org/api/latest/Classes/RKResponseDescriptor.html) class, which is responsible for linking the object mapping system with HTTP responses. It is important to keep in mind that the object mapping engine is completely independent of dependencies on HTTP -- it's a generalized system for describing and executing the transformation of objects across representations. HTTP just happens to be a very common transport mechanism for object representations.
`RKResponseDescriptor` lets you describe the circumstances in which a given object mapping should be used to process an HTTP response. There are three properties available for configuration:
`RKResponseDescriptor` lets you describe the circumstances in which a given object mapping should be used to process an HTTP response. There are four properties available for configuration:
* `pathPattern` - The path pattern is a specially formatted string that is matched against the URL from which the HTTP response was loaded. The pattern can contain colon delimited dynamic components that identify the parts of your URL that can change. For example, consider the following URL for a gist at Github: `https://api.github.com/gists/4774273`. Within this URL, `4774273` represents the ID of a particular gist. This is a dynamic component of the URL that can change from request to request, but we know that every time a response is loaded from `/gists/XXXX` that the response will contain a representation of a Gist object. We can configure the response descriptor to match this URL by configuring a path pattern that matches it: `/gists/:gistID`. The `gistID` is interpreted as a dynamic component because it is prefixed with a colon.
* `method` - The HTTP method to be used in the request. Enum options available are: RKRequestMethodPOST, RKRequestMethodPUT, RKRequestMethodDELETE, RKRequestMethodHEAD, RKRequestMethodPATCH, RKRequestMethodOPTIONS, RKRequestMethodAny
* `keyPath` - The key path identifies where in a parsed response document a given object representation may appear. Recall the previously mentioned importance of key-value coding. When a JSON or XML document is parsed, it is deserialized into an object graph structure composed of `NSArray` and `NSDictionary` objects. This object graph can be traversed using key-value coding. The key-path specified by the response descriptor tells RestKit that a given mapping applies to the subset of a deserialized response that can be obtained by executing `valueForKeyPath:`. This enables you to map different object types out of a single response or process only the subset of a response that you are interested in.
* `statusCodes` - The `statusCodes` property is an [`NSIndexSet`](https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSIndexSet_Class/Reference/Reference.html) that specifies the set of HTTP response codes for which a mapping is to be applied. In a RESTful application, the HTTP response codes are used to indicate the success or failure of requests. You can configure a response descriptor to only match the HTTP response codes that you expect the server to return a given representation with. For most API interactions, you typically expect a successful response of 200 or 201, but anything in the 2xx status code class is defined as successful according to the HTTP standard. You can explicitly configure your own `NSIndexSet` specifying the status codes for your descriptor or you can use the RestKit provided helper functions such as `RKStatusCodeIndexSetForClass` to quickly construct common values (see [`RKHTTPUtilities.h`](https://github.com/RestKit/RestKit/blob/development/Code/ObjectMapping/RKHTTPUtilities.h)). The `statusCodes` property figured prominently into the configuration of error mapping, which we'll explore in detail later in the guide.
Expand Down

0 comments on commit 90e29af

Please sign in to comment.