RKResponse Class Reference
| Inherits from | NSObject |
| Declared in | RKResponse.h RKResponse.m |
Tasks
Creating a Response
-
– initWithRequest:Initializes a new response object for a REST request.
-
– initWithRequest:body:headers:Initializes a new response object from a cached request.
-
– initWithSynchronousRequest:URLResponse:body:error:Initializes a response object from the results of a synchronous request.
Accessing the Request
-
requestThe request that generated this response.
property -
URLThe URL the response was loaded from.
property
Accessing the Response Components
-
statusCodeThe status code of the HTTP response.
property -
allHeaderFieldsReturn a dictionary of headers sent with the HTTP response.
property -
cookiesAn NSArray of NSHTTPCookie objects associated with the response.
property -
– localizedStatusCodeStringReturns the localized human readable representation of the HTTP Status Code returned.
Accessing Common Headers
-
– contentTypeReturns the value of ‘Content-Type’ HTTP header
-
– contentLengthReturns the value of the ‘Content-Length’ HTTP header
-
– locationReturns the value of the ‘Location’ HTTP Header
Reading the Body Content
-
bodyThe data returned as the response body.
property -
– bodyAsStringReturns the response body as an NSString
-
– bodyAsJSONReturns the response body parsed as JSON into an object
-
– parsedBody:Returns the response body parsed as JSON into an object
Handling Errors
-
failureErrorThe error returned if the URL connection fails.
property -
– failureErrorDescriptionDetermines if there is an error object and uses it’s localized message
-
– wasLoadedFromCacheIndicates whether the response was loaded from RKCache
Determining the Status Range of the Response
-
– isFailureIndicates that the connection failed to reach the remote server. The details of the failure are available on the failureError reader.
-
– isInvalidIndicates an invalid HTTP response code less than 100 or greater than 600
-
– isInformationalIndicates an informational HTTP response code between 100 and 199
-
– isSuccessfulIndicates an HTTP response code between 200 and 299.
-
– isRedirectionIndicates an HTTP response code between 300 and 399.
-
– isClientErrorIndicates an HTTP response code between 400 and 499.
-
– isServerErrorIndicates an HTTP response code between 500 and 599.
Determining Specific Statuses
-
– isErrorIndicates that the response is either a server or a client error.
-
– isOKIndicates an HTTP response code of 200.
-
– isCreatedIndicates an HTTP response code of 201.
-
– isNoContentIndicates an HTTP response code of 204.
-
– isNotModifiedIndicates an HTTP response code of 304.
-
– isUnauthorizedIndicates an HTTP response code of 401.
-
– isForbiddenIndicates an HTTP response code of 403.
-
– isNotFoundIndicates an HTTP response code of 404.
-
– isConflictIndicates an HTTP response code of 409.
-
– isGoneIndicates an HTTP response code of 410.
-
– isUnprocessableEntityIndicates an HTTP response code of 422.
-
– isRedirectIndicates an HTTP response code of 301, 302, 303 or 307.
-
– isEmptyIndicates an empty HTTP response code of 201, 204, or 304
-
– isServiceUnavailableIndicates an HTTP response code of 503
Accessing the Response's MIME Type and Encoding
-
MIMETypeThe MIME Type of the response body.
property -
– isHTMLTrue when the server turned an HTML response.
-
– isXHTMLTrue when the server turned an XHTML response
-
– isXMLTrue when the server turned an XML response
-
– isJSONTrue when the server turned an JSON response
-
– bodyEncodingNameReturns the name of the string encoding used for the response body
-
– bodyEncodingReturns the string encoding used for the response body
Properties
MIMEType
The MIME Type of the response body.
@property (nonatomic, readonly) NSString *MIMETypeDeclared In
RKResponse.hURL
The URL the response was loaded from.
@property (nonatomic, readonly) NSURL *URLDeclared In
RKResponse.hallHeaderFields
Return a dictionary of headers sent with the HTTP response.
@property (nonatomic, readonly) NSDictionary *allHeaderFieldsDeclared In
RKResponse.hbody
The data returned as the response body.
@property (nonatomic, readonly) NSData *bodyDeclared In
RKResponse.hcookies
An NSArray of NSHTTPCookie objects associated with the response.
@property (nonatomic, readonly) NSArray *cookiesDeclared In
RKResponse.hfailureError
The error returned if the URL connection fails.
@property (nonatomic, readonly) NSError *failureErrorDeclared In
RKResponse.hInstance Methods
bodyAsJSON
Returns the response body parsed as JSON into an object
- (id)bodyAsJSONDiscussion
Bug: DEPRECATED in v0.10.0
Declared In
RKResponse.hbodyAsString
Returns the response body as an NSString
- (NSString *)bodyAsStringDeclared In
RKResponse.hbodyEncoding
Returns the string encoding used for the response body
- (NSStringEncoding)bodyEncodingDeclared In
RKResponse.hbodyEncodingName
Returns the name of the string encoding used for the response body
- (NSString *)bodyEncodingNameDeclared In
RKResponse.hcontentLength
Returns the value of the ‘Content-Length’ HTTP header
- (NSString *)contentLengthDeclared In
RKResponse.hcontentType
Returns the value of ‘Content-Type’ HTTP header
- (NSString *)contentTypeDeclared In
RKResponse.hfailureErrorDescription
Determines if there is an error object and uses it’s localized message
- (NSString *)failureErrorDescriptionReturn Value
A string of the localized error message.
Declared In
RKResponse.hinitWithRequest:
Initializes a new response object for a REST request.
- (id)initWithRequest:(RKRequest *)requestParameters
- request
The request that the response being created belongs to.
Return Value
An RKResponse object with the request parameter set.
Declared In
RKResponse.hinitWithRequest:body:headers:
Initializes a new response object from a cached request.
- (id)initWithRequest:(RKRequest *)request body:(NSData *)body headers:(NSDictionary *)headersParameters
- request
The request that the response being created belongs to.
- body
The data of the body of the response.
- headers
A dictionary of the response’s headers.
Declared In
RKResponse.hinitWithSynchronousRequest:URLResponse:body:error:
Initializes a response object from the results of a synchronous request.
- (id)initWithSynchronousRequest:(RKRequest *)request URLResponse:(NSHTTPURLResponse *)URLResponse body:(NSData *)body error:(NSError *)errorParameters
- request
The request that the response being created belongs to.
- URLResponse
The response from the NSURLConnection call containing the headers and HTTP status code.
- body
The data of the body of the response.
- error
The error returned from the NSURLConnection call, if any.
Return Value
An RKResponse object with the results of the synchronous request derived from the NSHTTPURLResponse and body passed.
Declared In
RKResponse.hisClientError
Indicates an HTTP response code between 400 and 499.
- (BOOL)isClientErrorReturn Value
YES if the HTTP response code is between 400 and 499.
Discussion
This status code is indented for cases in which the client seems to have erred.
Declared In
RKResponse.hisConflict
Indicates an HTTP response code of 409.
- (BOOL)isConflictReturn Value
YES if the response is 409 Conflict.
Declared In
RKResponse.hisCreated
Indicates an HTTP response code of 201.
- (BOOL)isCreatedReturn Value
YES if the response is 201 Created.
Declared In
RKResponse.hisEmpty
Indicates an empty HTTP response code of 201, 204, or 304
- (BOOL)isEmptyReturn Value
YES if the response body is empty.
Declared In
RKResponse.hisError
Indicates that the response is either a server or a client error.
- (BOOL)isErrorReturn Value
YES if the response is either a server or client error, with a response code between 400 and 599.
Declared In
RKResponse.hisFailure
Indicates that the connection failed to reach the remote server. The details of the failure are available on the failureError reader.
- (BOOL)isFailureReturn Value
YES if the connection failed to reach the remote server.
Declared In
RKResponse.hisForbidden
Indicates an HTTP response code of 403.
- (BOOL)isForbiddenReturn Value
YES if the response is 403 Forbidden.
Declared In
RKResponse.hisGone
Indicates an HTTP response code of 410.
- (BOOL)isGoneReturn Value
YES if the response is 410 Gone.
Declared In
RKResponse.hisHTML
True when the server turned an HTML response.
- (BOOL)isHTMLReturn Value
YES when the MIME type is text/html.
Declared In
RKResponse.hisInformational
Indicates an informational HTTP response code between 100 and 199
- (BOOL)isInformationalReturn Value
YES if the HTTP response code is between 100 and 199
Declared In
RKResponse.hisInvalid
Indicates an invalid HTTP response code less than 100 or greater than 600
- (BOOL)isInvalidReturn Value
YES if the HTTP response code is less than 100 or greater than 600
Declared In
RKResponse.hisJSON
True when the server turned an JSON response
- (BOOL)isJSONReturn Value
YES when the MIME type is application/json.
Declared In
RKResponse.hisNoContent
Indicates an HTTP response code of 204.
- (BOOL)isNoContentReturn Value
YES if the response is 204 No Content.
Declared In
RKResponse.hisNotFound
Indicates an HTTP response code of 404.
- (BOOL)isNotFoundReturn Value
YES if the response is 404 Not Found.
Declared In
RKResponse.hisNotModified
Indicates an HTTP response code of 304.
- (BOOL)isNotModifiedReturn Value
YES if the response is 304 Not Modified.
Declared In
RKResponse.hisOK
Indicates an HTTP response code of 200.
- (BOOL)isOKReturn Value
YES if the response is 200 OK.
Declared In
RKResponse.hisRedirect
Indicates an HTTP response code of 301, 302, 303 or 307.
- (BOOL)isRedirectReturn Value
YES if the response requires a redirect to finish processing.
Declared In
RKResponse.hisRedirection
Indicates an HTTP response code between 300 and 399.
- (BOOL)isRedirectionReturn Value
YES if the HTTP response code is between 300 and 399.
Discussion
This class of status code indicates that further action needs to be taken by the user agent in order to fulfil the request. The action required may be carried out by the user agent without interaction with the user if and only if the method used in the second request is GET or HEAD.
Declared In
RKResponse.hisServerError
Indicates an HTTP response code between 500 and 599.
- (BOOL)isServerErrorReturn Value
YES if the HTTP response code is between 500 and 599.
Discussion
This state code occurs when the server failed to fulfill an apparently valid request.
Declared In
RKResponse.hisServiceUnavailable
Indicates an HTTP response code of 503
- (BOOL)isServiceUnavailableReturn Value
YES if the response is 503 Service Unavailable.
Declared In
RKResponse.hisSuccessful
Indicates an HTTP response code between 200 and 299.
- (BOOL)isSuccessfulReturn Value
YES if the HTTP response code is between 200 and 299
Discussion
Confirms that the server received, understood, accepted and processed the request successfully.
Declared In
RKResponse.hisUnauthorized
Indicates an HTTP response code of 401.
- (BOOL)isUnauthorizedReturn Value
YES if the response is 401 Unauthorized.
Declared In
RKResponse.hisUnprocessableEntity
Indicates an HTTP response code of 422.
- (BOOL)isUnprocessableEntityReturn Value
YES if the response is 422 Unprocessable Entity.
Declared In
RKResponse.hisXHTML
True when the server turned an XHTML response
- (BOOL)isXHTMLReturn Value
YES when the MIME type is application/xhtml+xml.
Declared In
RKResponse.hisXML
True when the server turned an XML response
- (BOOL)isXMLReturn Value
YES when the MIME type is application/xml.
Declared In
RKResponse.hlocalizedStatusCodeString
Returns the localized human readable representation of the HTTP Status Code returned.
- (NSString *)localizedStatusCodeStringDeclared In
RKResponse.hlocation
Returns the value of the ‘Location’ HTTP Header
- (NSString *)locationDeclared In
RKResponse.h