RKURL Class Reference
Inherits from | NSURL |
Declared in | RKURL.h RKURL.m |
Overview
RKURL extends the Cocoa NSURL base class to provide support for the concepts of base URL and resource path that are used extensively throughout the RestKit framework. RKURL is immutable, but provides numerous methods for constructing new RKURL instances where the received becomes the baseURL of the RKURL instance.
Instances of RKURL are aware of:
- the baseURL they were constructed against, if any
- the resource path that was appended to that baseURL
- any query parameters present in the URL
Example
NSDictionary *queryParams;
queryParams = [NSDictionary dictionaryWithObjectsAndKeys:@"pitbull", @"username",
@"pickles", @"password", nil];
RKURL *URL = [RKURL URLWithBaseURLString:@"http://restkit.org"
resourcePath:@"/test"
queryParameters:queryParams];
Tasks
Creating an RKURL
-
+ URLWithBaseURL:
Creates and returns an RKURL object intialized with a provided base URL.
-
+ URLWithBaseURL:resourcePath:
Creates and returns an RKURL object intialized with a provided base URL and resource path.
-
+ URLWithBaseURL:resourcePath:queryParameters:
Creates and returns an RKURL object intialized with a provided base URL, resource path, and a dictionary of query parameters.
-
+ URLWithBaseURLString:
Creates and returns an RKURL object intialized with a base URL constructed from the specified base URL string.
-
+ URLWithBaseURLString:resourcePath:
Creates and returns an RKURL object intialized with a base URL constructed from the specified base URL string and resource path.
-
+ URLWithBaseURLString:resourcePath:queryParameters:
Creates and returns an RKURL object intialized with a base URL constructed from the specified base URL string, resource path and a dictionary of query parameters.
-
– initWithBaseURL:resourcePath:queryParameters:
Initializes an RKURL object with a base URL, a resource path string, and a dictionary of query parameters.
Accessing the URL parts
-
baseURL
Returns the base URL of the receiver.
property -
resourcePath
Returns the resource path of the receiver.
property -
queryParameters
Returns the query component of a URL conforming to RFC 1808 as a dictionary.
property
Modifying the URL
-
– URLByAppendingResourcePath:
Returns a new RKURL object with a new resource path appended to its path.
-
– URLByAppendingResourcePath:queryParameters:
Returns a new RKURL object with a new resource path appended to its path and a dictionary of query parameters merged with the existing query component.
-
– URLByAppendingQueryParameters:
Returns a new RKURL object with a dictionary of query parameters merged with the existing query component.
-
– URLByReplacingResourcePath:
Returns a new RKURL object with the baseURL of the receiver and a new resourcePath.
-
– URLByInterpolatingResourcePathWithObject:
Returns a new RKURL object with its resource path processed as a pattern and evaluated against the specified object.
Properties
baseURL
Returns the base URL of the receiver.
@property (nonatomic, copy, readonly) NSURL *baseURL
Discussion
The base URL includes everything up to the resource path, typically the portion that is repeated in every API call.
Declared In
RKURL.h
queryParameters
Returns the query component of a URL conforming to RFC 1808 as a dictionary.
@property (nonatomic, readonly) NSDictionary *queryParameters
Discussion
If the receiver does not conform to RFC 1808, returns nil just as
NSURL query
does.
Declared In
RKURL.h
resourcePath
Returns the resource path of the receiver.
@property (nonatomic, copy, readonly) NSString *resourcePath
Discussion
The resource path is the path portion of the complete URL beyond that contained in the baseURL.
Declared In
RKURL.h
Class Methods
URLWithBaseURL:
Creates and returns an RKURL object intialized with a provided base URL.
+ (id)URLWithBaseURL:(NSURL *)baseURL
Parameters
- baseURL
The URL object with which to initialize the RKURL object.
Return Value
An RKURL object initialized with baseURL.
Declared In
RKURL.h
URLWithBaseURL:resourcePath:
Creates and returns an RKURL object intialized with a provided base URL and resource path.
+ (id)URLWithBaseURL:(NSURL *)baseURL resourcePath:(NSString *)resourcePath
Parameters
- baseURL
The URL object with which to initialize the RKURL object.
- resourcePath
The resource path for the RKURL object.
Return Value
An RKURL object initialized with baseURL and resourcePath.
Declared In
RKURL.h
URLWithBaseURL:resourcePath:queryParameters:
Creates and returns an RKURL object intialized with a provided base URL, resource path, and a dictionary of query parameters.
+ (id)URLWithBaseURL:(NSURL *)baseURL resourcePath:(NSString *)resourcePath queryParameters:(NSDictionary *)queryParameters
Parameters
- baseURL
The URL object with which to initialize the RKURL object.
- resourcePath
The resource path for the RKURL object.
- queryParameters
The query parameters for the RKURL object.
Return Value
An RKURL object initialized with baseURL, resourcePath, and queryParameters.
Declared In
RKURL.h
URLWithBaseURLString:
Creates and returns an RKURL object intialized with a base URL constructed from the specified base URL string.
+ (id)URLWithBaseURLString:(NSString *)baseURLString
Parameters
- baseURLString
The string with which to initialize the RKURL object.
Return Value
An RKURL object initialized with baseURLString.
Declared In
RKURL.h
URLWithBaseURLString:resourcePath:
Creates and returns an RKURL object intialized with a base URL constructed from the specified base URL string and resource path.
+ (id)URLWithBaseURLString:(NSString *)baseURLString resourcePath:(NSString *)resourcePath
Parameters
- baseURLString
The string with which to initialize the RKURL object.
- resourcePath
The resource path for the RKURL object.
Return Value
An RKURL object initialized with baseURLString and resourcePath.
Declared In
RKURL.h
URLWithBaseURLString:resourcePath:queryParameters:
Creates and returns an RKURL object intialized with a base URL constructed from the specified base URL string, resource path and a dictionary of query parameters.
+ (id)URLWithBaseURLString:(NSString *)baseURLString resourcePath:(NSString *)resourcePath queryParameters:(NSDictionary *)queryParameters
Parameters
- baseURLString
The string with which to initialize the RKURL object.
- resourcePath
The resource path for the RKURL object.
- queryParameters
The query parameters for the RKURL object.
Return Value
An RKURL object initialized with baseURLString, resourcePath and queryParameters.
Declared In
RKURL.h
Instance Methods
URLByAppendingQueryParameters:
Returns a new RKURL object with a dictionary of query parameters merged with the existing query component.
- (RKURL *)URLByAppendingQueryParameters:(NSDictionary *)theQueryParameters
Parameters
- theQueryParameters
A dictionary of query parameters to merge with any existing query parameters.
Return Value
A new RKURL that refers to the same resource as the receiver with a new query component including the values from theQueryParameters.
Declared In
RKURL.h
URLByAppendingResourcePath:
Returns a new RKURL object with a new resource path appended to its path.
- (RKURL *)URLByAppendingResourcePath:(NSString *)theResourcePath
Parameters
- theResourcePath
The resource path to append to the receiver’s path.
Return Value
A new RKURL that refers to a new resource at theResourcePath.
Declared In
RKURL.h
URLByAppendingResourcePath:queryParameters:
Returns a new RKURL object with a new resource path appended to its path and a dictionary of query parameters merged with the existing query component.
- (RKURL *)URLByAppendingResourcePath:(NSString *)theResourcePath queryParameters:(NSDictionary *)theQueryParameters
Parameters
- theResourcePath
The resource path to append to the receiver’s path.
- theQueryParameters
A dictionary of query parameters to merge with any existing query parameters.
Return Value
A new RKURL that refers to a new resource at theResourcePath with a new query component including the values from theQueryParameters.
Declared In
RKURL.h
URLByInterpolatingResourcePathWithObject:
Returns a new RKURL object with its resource path processed as a pattern and evaluated against the specified object.
- (RKURL *)URLByInterpolatingResourcePathWithObject:(id)object
Parameters
- object
The object to call methods on for the pattern strings in the resource path.
Return Value
A new RKURL object with its resource path evaluated as a pattern and interpolated with properties of object.
Discussion
Resource paths may contain pattern strings prefixed by colons (“:”) that refer to key-value coding accessible properties on the provided object.
For example:
// Given an RKURL initialized as:
RKURL *myURL = [RKURL URLWithBaseURLString:@"http://restkit.org"
resourcePath:@"/paginate?per_page=:perPage&page=:page"];
// And a dictionary containing values:
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:@"25", @"perPage",
@"5", @"page", nil];
// A new RKURL can be constructed by interpolating the dictionary with the original URL
RKURL *interpolatedURL = [myURL URLByInterpolatingResourcePathWithObject:dictionary];
The absoluteString of this new URL would be:
http://restkit.org/paginate?per_page=25&page=5
See Also
Declared In
RKURL.h
URLByReplacingResourcePath:
Returns a new RKURL object with the baseURL of the receiver and a new resourcePath.
- (RKURL *)URLByReplacingResourcePath:(NSString *)newResourcePath
Parameters
- newResourcePath
The resource path to replace the value of resourcePath in the new RKURL object.
Return Value
An RKURL object with newResourcePath appended to the receiver’s baseURL.
Declared In
RKURL.h
initWithBaseURL:resourcePath:queryParameters:
Initializes an RKURL object with a base URL, a resource path string, and a dictionary of query parameters.
- (id)initWithBaseURL:(NSURL *)theBaseURL resourcePath:(NSString *)theResourcePath queryParameters:(NSDictionary *)theQueryParameters
Parameters
- theBaseURL
The NSURL with which to initialize the RKURL object.
- theResourcePath
The resource path for the RKURL object.
- theQueryParameters
The query parameters for the RKURL object.
Return Value
An RKURL object initialized with baseURL, resourcePath and queryParameters.
Discussion
initWithBaseURL:resourcePath:queryParameters:
is the designated initializer.
Declared In
RKURL.h