RKRequest Class Reference
| Inherits from | NSObject |
| Declared in | RKRequest.h RKRequest.m |
Tasks
Creating a Request
-
+ requestWithURL:Creates and returns a RKRequest object initialized to load content from a provided URL.
-
– initWithURL:Initializes a RKRequest object to load from a provided URL
-
+ requestWithURL:delegate:Creates and returns a RKRequest object initialized to load content from a provided URL with a specified delegate.
-
– initWithURL:delegate:Initializes a RKRequest object to load from a provided URL
Setting Properties
-
URLThe URL this request is loading
property -
resourcePathThe resourcePath portion of the request’s URL
property -
methodThe HTTP verb in which the request is sent
property -
HTTPMethodReturns HTTP method as a string used for this request.
property -
responseThe response returned when the receiver was sent.
property -
paramsA serializable collection of parameters sent as the HTTP body of the request
property -
additionalHTTPHeadersA dictionary of additional HTTP Headers to send with the request
property -
runLoopModeThe run loop mode under which the underlying NSURLConnection is performed
property -
userDataAn opaque pointer to associate user defined data with the request.
property -
URLRequestThe underlying NSMutableURLRequest sent for this request
property -
defaultHTTPEncodingThe default value used to decode HTTP body content when HTTP headers received do not provide information on the content. This encoding will be used by the RKResponse when creating the body content
property
Working with the HTTP Body
-
– setBody:forMIMEType:Sets the request body using the provided NSDictionary after passing the NSDictionary through serialization using the currently configured parser for the provided MIMEType.
-
HTTPBodyThe HTTP body as a NSData used for this request
property -
HTTPBodyStringThe HTTP body as a string used for this request
property
Delegates
-
delegateThe delegate to inform when the request is completed
property -
configurationDelegateA delegate responsible for configuring the request. Centralizes common configuration data (such as HTTP headers, authentication information, etc) for re-use.
property
Handling Blocks
-
onDidLoadResponseproperty -
onDidFailLoadWithErrorA block to invoke when the receuver has failed loading due to an error.
property -
followRedirectWhether this request should follow server redirects or not.
property
Background Tasks
-
backgroundPolicyThe policy to take on transition to the background (iOS 4.x and higher only)
property -
backgroundTaskIdentifierReturns the identifier of the task that has been sent to the background.
property
Authentication
-
authenticationTypeThe type of authentication to use for this request.
property -
usernameThe username to use for authentication via HTTP AUTH.
property -
passwordThe password to use for authentication via HTTP AUTH.
property
OAuth1 Secrets
-
OAuth1ConsumerKeyThe OAuth 1.0 consumer key
property -
OAuth1ConsumerSecretThe OAuth 1.0 consumer secret
property -
OAuth1AccessTokenThe OAuth 1.0 access token
property -
OAuth1AccessTokenSecretThe OAuth 1.0 access token secret
property
OAuth2 Secrets
-
OAuth2AccessTokenThe OAuth 2.0 access token
property -
OAuth2RefreshTokenThe OAuth 2.0 refresh token
property
Caching
-
cacheKeyReturns the cache key for getting/setting the cache entry for this request in the cache.
property -
cachePolicyThe cache policy used when storing this request into the request cache
property -
cacheThe request cache to store and load responses for this request.
property -
– isCacheableReturns YES if the request is cacheable
-
cacheTimeoutIntervalThe timeout interval within which the request should not be sent and the cached response should be used. Used if the cache policy includes RKRequestCachePolicyTimeout.
property
Handling SSL Validation
-
disableCertificateValidationFlag for disabling SSL certificate validation.
property -
additionalRootCertificatesA set of additional certificates to be used in evaluating server SSL certificates.
property
Sending and Managing the Request
-
– prepareURLRequest -
queueThe request queue that this request belongs to
property -
– sendSend the request asynchronously. It will be added to the queue and dispatched as soon as possible.
-
– sendAsynchronouslyImmediately dispatch a request asynchronously, skipping the request queue.
-
– sendSynchronouslySend the request synchronously and return a hydrated response object.
-
cancelledReturns a Boolean value indicating whether the request has been cancelled.
property -
– cancelCancels the underlying URL connection.
-
reachabilityObserverThe reachability observer to consult for network status. Used for performing offline cache loads.
property
Resetting the State
Callbacks
-
– didFailLoadWithError:Callback performed to notify the request that the underlying NSURLConnection has failed with an error.
-
– didFinishLoad:Callback performed to notify the request that the underlying NSURLConnection has completed with a response.
Timing Out the Request
-
timeoutIntervalThe timeout interval within which the request should be cancelled if no data has been received.
property -
– createTimeoutTimer -
– timeoutCancels request due to connection timeout exceeded.
-
– invalidateTimeoutTimerInvalidates the timeout timer.
Determining the Request Type and State
-
– isGETReturns YES when this is a GET request
-
– isPOSTReturns YES when this is a POST request
-
– isPUTReturns YES when this is a PUT request
-
– isDELETEReturns YES when this is a DELETE request
-
– isHEADReturns YES when this is a HEAD request
-
loadingReturns YES when this request is in-progress
property -
loadedReturns YES when this request has been completed
property -
– isUnsentReturns YES when this request has not yet been sent
-
– wasSentToResourcePath:Returns YES when the request was sent to the specified resource path
-
– wasSentToResourcePath:method:Returns YES when the receiver was sent to the specified resource path with a given request method.
Properties
HTTPBody
The HTTP body as a NSData used for this request
@property (nonatomic, retain) NSData *HTTPBodyDeclared In
RKRequest.hHTTPBodyString
The HTTP body as a string used for this request
@property (nonatomic, retain) NSString *HTTPBodyStringDeclared In
RKRequest.hHTTPMethod
Returns HTTP method as a string used for this request.
@property (nonatomic, readonly) NSString *HTTPMethodDiscussion
This should be set through the method property using an RKRequestMethod type.
See Also
Declared In
RKRequest.hOAuth1AccessToken
The OAuth 1.0 access token
@property (nonatomic, retain) NSString *OAuth1AccessTokenDiscussion
Used to build an Authorization header when authenticationType is RKRequestAuthenticationTypeOAuth1
See Also
Declared In
RKRequest.hOAuth1AccessTokenSecret
The OAuth 1.0 access token secret
@property (nonatomic, retain) NSString *OAuth1AccessTokenSecretDiscussion
Used to build an Authorization header when authenticationType is RKRequestAuthenticationTypeOAuth1
See Also
Declared In
RKRequest.hOAuth1ConsumerKey
The OAuth 1.0 consumer key
@property (nonatomic, retain) NSString *OAuth1ConsumerKeyDiscussion
Used to build an Authorization header when authenticationType is RKRequestAuthenticationTypeOAuth1
See Also
Declared In
RKRequest.hOAuth1ConsumerSecret
The OAuth 1.0 consumer secret
@property (nonatomic, retain) NSString *OAuth1ConsumerSecretDiscussion
Used to build an Authorization header when authenticationType is RKRequestAuthenticationTypeOAuth1
See Also
Declared In
RKRequest.hOAuth2AccessToken
The OAuth 2.0 access token
@property (nonatomic, retain) NSString *OAuth2AccessTokenDiscussion
Used to build an Authorization header when authenticationType is RKRequestAuthenticationTypeOAuth2
See Also
Declared In
RKRequest.hOAuth2RefreshToken
The OAuth 2.0 refresh token
@property (nonatomic, retain) NSString *OAuth2RefreshTokenDiscussion
Used to retrieve a new access token before expiration and to build an Authorization header when authenticationType is RKRequestAuthenticationTypeOAuth2
Bug: NOT IMPLEMENTED: This functionality is not yet implemented.
See Also
Declared In
RKRequest.hURL
The URL this request is loading
@property (nonatomic, retain) NSURL *URLDeclared In
RKRequest.hURLRequest
The underlying NSMutableURLRequest sent for this request
@property (nonatomic, readonly) NSMutableURLRequest *URLRequestDeclared In
RKRequest.hadditionalHTTPHeaders
A dictionary of additional HTTP Headers to send with the request
@property (nonatomic, retain) NSDictionary *additionalHTTPHeadersDeclared In
RKRequest.hadditionalRootCertificates
A set of additional certificates to be used in evaluating server SSL certificates.
@property (nonatomic, retain) NSSet *additionalRootCertificatesDeclared In
RKRequest.hauthenticationType
The type of authentication to use for this request.
@property (nonatomic, assign) RKRequestAuthenticationType authenticationTypeDiscussion
This must be assigned one of the following:
RKRequestAuthenticationTypeNone: Disable the use of authenticationRKRequestAuthenticationTypeHTTP: Use NSURLConnection’s HTTP AUTH auto-negotiationRKRequestAuthenticationTypeHTTPBasic: Force the use of HTTP Basic authentication. This will supress AUTH challenges as RestKit will add an Authorization header establishing login via HTTP basic. This is an optimization that skips the challenge portion of the request.RKRequestAuthenticationTypeOAuth1: Enable the use of OAuth 1.0 authentication. OAuth1ConsumerKey, OAuth1ConsumerSecret, OAuth1AccessToken, and OAuth1AccessTokenSecret must be set.RKRequestAuthenticationTypeOAuth2: Enable the use of OAuth 2.0 authentication. OAuth2AccessToken must be set.
Default: RKRequestAuthenticationTypeNone
Declared In
RKRequest.hbackgroundPolicy
The policy to take on transition to the background (iOS 4.x and higher only)
@property (nonatomic, assign) RKRequestBackgroundPolicy backgroundPolicyDiscussion
Default: RKRequestBackgroundPolicyCancel
Declared In
RKRequest.hbackgroundTaskIdentifier
Returns the identifier of the task that has been sent to the background.
@property (nonatomic, readonly) UIBackgroundTaskIdentifier backgroundTaskIdentifierDeclared In
RKRequest.hcache
The request cache to store and load responses for this request.
@property (nonatomic, retain) RKRequestCache *cacheDiscussion
Generally configured by the RKClient instance that minted this request
This must be assigned one of the following:
RKRequestCachePolicyNone: Never use the cache.RKRequestCachePolicyLoadIfOffline: Load from the cache when offline.RKRequestCachePolicyLoadOnError: Load from the cache if an error is encountered.RKRequestCachePolicyEtag: Load from the cache if there is data stored and the server returns a 304 (Not Modified) response.RKRequestCachePolicyEnabled: Load from the cache whenever data has been stored.RKRequestCachePolicyTimeout: Load from the cache if the cacheTimeoutInterval is reached before the server responds.
Declared In
RKRequest.hcacheKey
@property (nonatomic, readonly) NSString *cacheKeyDiscussion
The cacheKey is an MD5 value computed by hashing a combination of the destination URL, the HTTP verb, and the request body (when possible).
Declared In
RKRequest.hcacheTimeoutInterval
The timeout interval within which the request should not be sent and the cached response should be used. Used if the cache policy includes RKRequestCachePolicyTimeout.
@property (nonatomic, assign) NSTimeInterval cacheTimeoutIntervalDeclared In
RKRequest.hcancelled
Returns a Boolean value indicating whether the request has been cancelled.
@property (nonatomic, assign, readonly, getter=isCancelled) BOOL cancelledReturn Value
YES if the request was sent a cancel message, otherwise NO.
Declared In
RKRequest.hconfigurationDelegate
A delegate responsible for configuring the request. Centralizes common configuration data (such as HTTP headers, authentication information, etc) for re-use.
@property (nonatomic, assign) id<> configurationDelegateDiscussion
RKClient and RKObjectManager conform to the RKConfigurationDelegate protocol. Request and object loader instances built through these objects will have a reference to their parent client/object manager assigned as the configuration delegate.
Default: nil
See Also
Declared In
RKRequest.hdefaultHTTPEncoding
The default value used to decode HTTP body content when HTTP headers received do not provide information on the content. This encoding will be used by the RKResponse when creating the body content
@property (nonatomic, assign) NSStringEncoding defaultHTTPEncodingDeclared In
RKRequest.hdelegate
The delegate to inform when the request is completed
@property (nonatomic, assign) id<> delegateDiscussion
If the object implements the RKRequestDelegate protocol, it will receive request lifecycle event messages.
Declared In
RKRequest.hdisableCertificateValidation
Flag for disabling SSL certificate validation.
@property (nonatomic, assign) BOOL disableCertificateValidationDiscussion
When YES, SSL certificates will not be validated.
Default: NO
Warning: WARNING: This is a potential security exposure and should be used ONLY while debugging in a controlled environment.
Declared In
RKRequest.hfollowRedirect
Whether this request should follow server redirects or not.
@property (nonatomic, assign) BOOL followRedirectDiscussion
@default YES
Declared In
RKRequest.hloaded
Returns YES when this request has been completed
@property (nonatomic, assign, readonly, getter=isLoaded) BOOL loadedDeclared In
RKRequest.hloading
Returns YES when this request is in-progress
@property (nonatomic, assign, readonly, getter=isLoading) BOOL loadingDeclared In
RKRequest.hmethod
The HTTP verb in which the request is sent
@property (nonatomic, assign) RKRequestMethod methodDiscussion
Default: RKRequestMethodGET
Declared In
RKRequest.honDidFailLoadWithError
A block to invoke when the receuver has failed loading due to an error.
@property (nonatomic, copy) RKRequestDidFailLoadWithErrorBlock onDidFailLoadWithErrorDeclared In
RKRequest.honDidLoadResponse
@property (nonatomic, copy) RKRequestDidLoadResponseBlock onDidLoadResponseDeclared In
RKRequest.hparams
A serializable collection of parameters sent as the HTTP body of the request
@property (nonatomic, retain) NSObject<RKRequestSerializable> *paramsDeclared In
RKRequest.hpassword
The password to use for authentication via HTTP AUTH.
@property (nonatomic, retain) NSString *passwordDiscussion
Used to respond to an authentication challenge when authenticationType is RKRequestAuthenticationTypeHTTP or RKRequestAuthenticationTypeHTTPBasic.
See Also
Declared In
RKRequest.hqueue
The request queue that this request belongs to
@property (nonatomic, assign) RKRequestQueue *queueDeclared In
RKRequest.hreachabilityObserver
The reachability observer to consult for network status. Used for performing offline cache loads.
@property (nonatomic, retain) RKReachabilityObserver *reachabilityObserverDiscussion
Generally configured by the RKClient instance that minted this request.
Declared In
RKRequest.hresourcePath
The resourcePath portion of the request’s URL
@property (nonatomic, retain) NSString *resourcePathDeclared In
RKRequest.hresponse
The response returned when the receiver was sent.
@property (nonatomic, retain, readonly) RKResponse *responseDeclared In
RKRequest.hrunLoopMode
The run loop mode under which the underlying NSURLConnection is performed
@property (nonatomic, copy) NSString *runLoopModeDiscussion
Default: NSRunLoopCommonModes
Declared In
RKRequest.htimeoutInterval
@property (nonatomic, assign) NSTimeInterval timeoutIntervalDiscussion
The timeout timer is cancelled as soon as we start receiving data and are expecting the request to finish.
Default: 120.0 seconds
Declared In
RKRequest.huserData
An opaque pointer to associate user defined data with the request.
@property (nonatomic, retain) id userDataDeclared In
RKRequest.husername
The username to use for authentication via HTTP AUTH.
@property (nonatomic, retain) NSString *usernameDiscussion
Used to respond to an authentication challenge when authenticationType is RKRequestAuthenticationTypeHTTP or RKRequestAuthenticationTypeHTTPBasic.
See Also
Declared In
RKRequest.hClass Methods
requestWithURL:
Creates and returns a RKRequest object initialized to load content from a provided URL.
+ (RKRequest *)requestWithURL:(NSURL *)URLParameters
- URL
The remote URL to load
Return Value
An autoreleased RKRequest object initialized with URL.
Declared In
RKRequest.hrequestWithURL:delegate:
Creates and returns a RKRequest object initialized to load content from a provided URL with a specified delegate.
+ (RKRequest *)requestWithURL:(NSURL *)URL delegate:(id)delegateParameters
- URL
The remote URL to load
Return Value
An autoreleased RKRequest object initialized with URL.
Discussion
Bug: DEPRECATED in v0.10.0: Use [RKRequest requestWithURL:] instead
Declared In
RKRequest.hInstance Methods
cancel
Cancels the underlying URL connection.
- (void)cancelDiscussion
This will call the requestDidCancel: delegate method if your delegate responds to it. This does not subsequently set the the request’s delegate to nil. However, it’s good practice to cancel the RKRequest and immediately set the delegate property to nil within the delegate’s dealloc method.
See Also
NSURLConnection:– cancel
Declared In
RKRequest.hcreateTimeoutTimer
- (void)createTimeoutTimerDiscussion
This is mainly used so we can test that the timer is only being created once.
Declared In
RKRequest.hdidFailLoadWithError:
Callback performed to notify the request that the underlying NSURLConnection has failed with an error.
- (void)didFailLoadWithError:(NSError *)errorParameters
- error
An NSError object containing the RKRestKitError that triggered the callback.
Declared In
RKRequest.hdidFinishLoad:
Callback performed to notify the request that the underlying NSURLConnection has completed with a response.
- (void)didFinishLoad:(RKResponse *)responseParameters
- response
An RKResponse object with the result of the request.
Declared In
RKRequest.hinitWithURL:
Initializes a RKRequest object to load from a provided URL
- (id)initWithURL:(NSURL *)URLParameters
- URL
The remote URL to load
Return Value
An RKRequest object initialized with URL.
Declared In
RKRequest.hinitWithURL:delegate:
Initializes a RKRequest object to load from a provided URL
- (id)initWithURL:(NSURL *)URL delegate:(id)delegateParameters
- URL
The remote URL to load
Return Value
An RKRequest object initialized with URL.
Discussion
Bug: DEPRECATED in v0.10.0: Use [RKRequest initWithURL:] instead
Declared In
RKRequest.hinvalidateTimeoutTimer
Invalidates the timeout timer.
- (void)invalidateTimeoutTimerDiscussion
Called by RKResponse when the NSURLConnection begins receiving data.
Declared In
RKRequest.hisCacheable
Returns YES if the request is cacheable
- (BOOL)isCacheableDiscussion
Only GET requests are considered cacheable (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html)..)
Declared In
RKRequest.hisUnsent
Returns YES when this request has not yet been sent
- (BOOL)isUnsentDeclared In
RKRequest.hsend
Send the request asynchronously. It will be added to the queue and dispatched as soon as possible.
- (void)sendDeclared In
RKRequest.hsendAsynchronously
Immediately dispatch a request asynchronously, skipping the request queue.
- (void)sendAsynchronouslyDeclared In
RKRequest.hsendSynchronously
Send the request synchronously and return a hydrated response object.
- (RKResponse *)sendSynchronouslyReturn Value
An RKResponse object with the result of the request.
Declared In
RKRequest.hsetBody:forMIMEType:
Sets the request body using the provided NSDictionary after passing the NSDictionary through serialization using the currently configured parser for the provided MIMEType.
- (void)setBody:(NSDictionary *)body forMIMEType:(NSString *)MIMETypeParameters
- body
An NSDictionary of key/value pairs to be serialized and sent as the HTTP body.
- MIMEType
The MIMEType for the parser to use for the dictionary.
Declared In
RKRequest.htimeout
Cancels request due to connection timeout exceeded.
- (void)timeoutDiscussion
This method is invoked by the timeoutTimer upon its expiration and will return an RKRequestConnectionTimeoutError via didFailLoadWithError:
Declared In
RKRequest.hwasSentToResourcePath:
Returns YES when the request was sent to the specified resource path
- (BOOL)wasSentToResourcePath:(NSString *)resourcePathParameters
- resourcePath
A string of the resource path that we want to check against
Declared In
RKRequest.hwasSentToResourcePath:method:
Returns YES when the receiver was sent to the specified resource path with a given request method.
- (BOOL)wasSentToResourcePath:(NSString *)resourcePath method:(RKRequestMethod)methodParameters
- resourcePath
A string of the resource path that we want to check against
- method
The HTTP method to confirm the request was sent with.
Declared In
RKRequest.h