Inherits from NSObject
Declared in RKResponseDescriptor.h

Overview

An RKResponseDescriptor object describes an object mapping configuration that is applicable to an HTTP response. Response descriptors are defined by specifying the RKMapping object that is to be used when performing object mapping on the deserialized response body and the URL path pattern, key path, and status codes for which the mapping is appropriate. The path pattern is a SOCKit SOCPattern string that will be matched against the URL of the request that loaded the response being mapped. If the path pattern is nil, the response descriptor is considered to be appropriate for a response loaded from any URL. The key path specifies the location of data within the deserialized response body for which the mapping is appropriate. If nil, the mapping is considered to apply to the entire response body. The status codes specify a set of HTTP response status codes for which the mapping is appropriate. It is common to constrain a response descriptor to the HTTP Successful status code class (status codes in the 200-299 range). Object mapping for error responses can be configured by configuring a response descriptor to handle the Client Error status code class (status codes in the 400-499 range). Instances of RKResponseDescriptor are immutable.

Tasks

Creating a Response Descriptor

Getting Information About a Response Descriptor

  •   mapping

    The mapping to be used when object mapping the deserialized HTTP response body. Cannot be nil.

    property
  •   pathPattern

    The path pattern to match against the request URL. If nil, the response descriptor matches any URL.

    property
  •   keyPath

    The key path to match against the deserialized response body. If nil, the response descriptor matches the entire response body.

    property
  •   statusCodes

    The set of status codes for which response descriptor matches. If nil, the the response descriptor matches any status code.

    property

Setting the Base URL

Using Response Descriptors

  • – matchesPath:

    Returns a Boolean value that indicates if the receiver’s path pattern matches the given path.

  • – matchesURL:

    Returns a Boolean value that indicates if the given URL object matches the base URL and path pattern of the receiver.

  • – matchesResponse:

    Returns a Boolean value that indicates if the given URL response object matches the receiver.

Properties

baseURL

The base URL that the pathPattern is to be evaluated relative to.

@property (nonatomic, copy) NSURL *baseURL

Discussion

The base URL is set to the base URL of the object manager when a response descriptor is added to an object manager.

Declared In

RKResponseDescriptor.h

keyPath

The key path to match against the deserialized response body. If nil, the response descriptor matches the entire response body.

@property (nonatomic, copy, readonly) NSString *keyPath

Discussion

When evaluating a key path match, the Foundation object parsed from the response body is sent valueForKeyPath: with the keyPath of the receiver. If the value returned is non-nil, object mapping is performed using the response descriptor’s mapping.

Declared In

RKResponseDescriptor.h

mapping

The mapping to be used when object mapping the deserialized HTTP response body. Cannot be nil.

@property (nonatomic, strong, readonly) RKMapping *mapping

Declared In

RKResponseDescriptor.h

pathPattern

The path pattern to match against the request URL. If nil, the response descriptor matches any URL.

@property (nonatomic, copy, readonly) NSString *pathPattern

Declared In

RKResponseDescriptor.h

statusCodes

The set of status codes for which response descriptor matches. If nil, the the response descriptor matches any status code.

@property (nonatomic, copy, readonly) NSIndexSet *statusCodes

Declared In

RKResponseDescriptor.h

Class Methods

responseDescriptorWithMapping:pathPattern:keyPath:statusCodes:

Creates and returns a new RKResponseDescriptor object.

+ (instancetype)responseDescriptorWithMapping:(RKMapping *)mapping pathPattern:(NSString *)pathPattern keyPath:(NSString *)keyPath statusCodes:(NSIndexSet *)statusCodes

Parameters

mapping

The mapping for the response descriptor.

pathPattern

A path pattern that matches against URLs for which the mapping should be used.

keyPath

A key path specifying the subset of the parsed response for which the mapping is to be used.

statusCodes

A set of HTTP status codes for which the mapping is to be used.

Return Value

A new RKResponseDescriptor object.

Declared In

RKResponseDescriptor.h

Instance Methods

matchesPath:

Returns a Boolean value that indicates if the receiver’s path pattern matches the given path.

- (BOOL)matchesPath:(NSString *)path

Parameters

path

The path to compare with the path pattern of the receiver.

Return Value

YES if the path matches the receiver’s pattern, else NO.

Discussion

Path matching is performed using an RKPathMatcher object. If the receiver has a nil path pattern or the given path is nil, YES is returned.

Declared In

RKResponseDescriptor.h

matchesResponse:

Returns a Boolean value that indicates if the given URL response object matches the receiver.

- (BOOL)matchesResponse:(NSHTTPURLResponse *)response

Parameters

response

The HTTP response object to compare with the base URL, path pattern, and status codes set of the receiver.

Return Value

YES if the response matches the base URL, path pattern, and status codes set of the receiver, else NO.

Discussion

The match is evaluated by checking if the URL of the response matches the base URL and path pattern of the receiver via the matchesURL: method. If the URL is found to match, then the status code of the response is checked for inclusion in the receiver’s set of status codes.

Declared In

RKResponseDescriptor.h

matchesURL:

Returns a Boolean value that indicates if the given URL object matches the base URL and path pattern of the receiver.

- (BOOL)matchesURL:(NSURL *)URL

Parameters

URL

The URL to compare with the base URL and path pattern of the receiver.

Return Value

YES if the URL matches the base URL and path pattern of the receiver, else NO.

Discussion

This method considers both the baseURL and pathPattern of the receiver when evaluating the given URL object. The results evaluate in the following ways:

  1. If the baseURL and pathPattern of the receiver are both nil, then YES is returned.
  2. If the baseURL of the receiver is nil, but the path pattern is not, then the entire path and query string of the given URL will be evaluated against the path pattern of the receiver using matchesPath:.
  3. If the baseURL and the pathPattern are both non-nil, then the given URL is first checked to verify that it is relative to the base URL using a string prefix comparison. If the absolute string value of the given URL is prefixed with the string value of the base URL, then the URL is considered relative. If the given URL is found not to be relative to the receiver’s baseURL, then NO is returned. If the URL is found to be relative to the base URL, then the path and query string of the URL are evaluated against the path pattern of the receiver using matchesPath:.

Declared In

RKResponseDescriptor.h