Inherits from NSObject
Declared in RKResponse.h
RKResponse.m

Overview

Models the response portion of an HTTP request/response cycle

Tasks

Creating a Response

Accessing the Request

  •   request

    The request that generated this response.

    property
  •   URL

    The URL the response was loaded from.

    property

Accessing the Response Components

Accessing Common Headers

Reading the Body Content

Handling Errors

Determining the Status Range of the Response

Determining Specific Statuses

Accessing the Response's MIME Type and Encoding

Properties

MIMEType

The MIME Type of the response body.

@property (nonatomic, readonly) NSString *MIMEType

Declared In

RKResponse.h

URL

The URL the response was loaded from.

@property (nonatomic, readonly) NSURL *URL

Declared In

RKResponse.h

allHeaderFields

Return a dictionary of headers sent with the HTTP response.

@property (nonatomic, readonly) NSDictionary *allHeaderFields

Declared In

RKResponse.h

body

The data returned as the response body.

@property (nonatomic, readonly) NSData *body

Declared In

RKResponse.h

cookies

An NSArray of NSHTTPCookie objects associated with the response.

@property (nonatomic, readonly) NSArray *cookies

Declared In

RKResponse.h

failureError

The error returned if the URL connection fails.

@property (nonatomic, readonly) NSError *failureError

Declared In

RKResponse.h

request

The request that generated this response.

@property (nonatomic, assign, readonly) RKRequest *request

Declared In

RKResponse.h

statusCode

The status code of the HTTP response.

@property (nonatomic, readonly) NSInteger statusCode

Declared In

RKResponse.h

Instance Methods

bodyAsJSON

Returns the response body parsed as JSON into an object

- (id)bodyAsJSON

Discussion

Bug: DEPRECATED in v0.10.0

Declared In

RKResponse.h

bodyAsString

Returns the response body as an NSString

- (NSString *)bodyAsString

Declared In

RKResponse.h

bodyEncoding

Returns the string encoding used for the response body

- (NSStringEncoding)bodyEncoding

Declared In

RKResponse.h

bodyEncodingName

Returns the name of the string encoding used for the response body

- (NSString *)bodyEncodingName

Declared In

RKResponse.h

contentLength

Returns the value of the ‘Content-Length’ HTTP header

- (NSString *)contentLength

Declared In

RKResponse.h

contentType

Returns the value of ‘Content-Type’ HTTP header

- (NSString *)contentType

Declared In

RKResponse.h

failureErrorDescription

Determines if there is an error object and uses it’s localized message

- (NSString *)failureErrorDescription

Return Value

A string of the localized error message.

Declared In

RKResponse.h

initWithRequest:

Initializes a new response object for a REST request.

- (id)initWithRequest:(RKRequest *)request

Parameters

request

The request that the response being created belongs to.

Return Value

An RKResponse object with the request parameter set.

Declared In

RKResponse.h

initWithRequest:body:headers:

Initializes a new response object from a cached request.

- (id)initWithRequest:(RKRequest *)request body:(NSData *)body headers:(NSDictionary *)headers

Parameters

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.

Return Value

An RKResponse object with the request, body, and header parameters set.

Declared In

RKResponse.h

initWithSynchronousRequest: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 *)error

Parameters

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.h

isClientError

Indicates an HTTP response code between 400 and 499.

- (BOOL)isClientError

Return 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.h

isConflict

Indicates an HTTP response code of 409.

- (BOOL)isConflict

Return Value

YES if the response is 409 Conflict.

Declared In

RKResponse.h

isCreated

Indicates an HTTP response code of 201.

- (BOOL)isCreated

Return Value

YES if the response is 201 Created.

Declared In

RKResponse.h

isEmpty

Indicates an empty HTTP response code of 201, 204, or 304

- (BOOL)isEmpty

Return Value

YES if the response body is empty.

Declared In

RKResponse.h

isError

Indicates that the response is either a server or a client error.

- (BOOL)isError

Return Value

YES if the response is either a server or client error, with a response code between 400 and 599.

Declared In

RKResponse.h

isFailure

Indicates that the connection failed to reach the remote server. The details of the failure are available on the failureError reader.

- (BOOL)isFailure

Return Value

YES if the connection failed to reach the remote server.

Declared In

RKResponse.h

isForbidden

Indicates an HTTP response code of 403.

- (BOOL)isForbidden

Return Value

YES if the response is 403 Forbidden.

Declared In

RKResponse.h

isGone

Indicates an HTTP response code of 410.

- (BOOL)isGone

Return Value

YES if the response is 410 Gone.

Declared In

RKResponse.h

isHTML

True when the server turned an HTML response.

- (BOOL)isHTML

Return Value

YES when the MIME type is text/html.

Declared In

RKResponse.h

isInformational

Indicates an informational HTTP response code between 100 and 199

- (BOOL)isInformational

Return Value

YES if the HTTP response code is between 100 and 199

Declared In

RKResponse.h

isInvalid

Indicates an invalid HTTP response code less than 100 or greater than 600

- (BOOL)isInvalid

Return Value

YES if the HTTP response code is less than 100 or greater than 600

Declared In

RKResponse.h

isJSON

True when the server turned an JSON response

- (BOOL)isJSON

Return Value

YES when the MIME type is application/json.

Declared In

RKResponse.h

isNoContent

Indicates an HTTP response code of 204.

- (BOOL)isNoContent

Return Value

YES if the response is 204 No Content.

Declared In

RKResponse.h

isNotFound

Indicates an HTTP response code of 404.

- (BOOL)isNotFound

Return Value

YES if the response is 404 Not Found.

Declared In

RKResponse.h

isNotModified

Indicates an HTTP response code of 304.

- (BOOL)isNotModified

Return Value

YES if the response is 304 Not Modified.

Declared In

RKResponse.h

isOK

Indicates an HTTP response code of 200.

- (BOOL)isOK

Return Value

YES if the response is 200 OK.

Declared In

RKResponse.h

isRedirect

Indicates an HTTP response code of 301, 302, 303 or 307.

- (BOOL)isRedirect

Return Value

YES if the response requires a redirect to finish processing.

Declared In

RKResponse.h

isRedirection

Indicates an HTTP response code between 300 and 399.

- (BOOL)isRedirection

Return 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.h

isServerError

Indicates an HTTP response code between 500 and 599.

- (BOOL)isServerError

Return 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.h

isServiceUnavailable

Indicates an HTTP response code of 503

- (BOOL)isServiceUnavailable

Return Value

YES if the response is 503 Service Unavailable.

Declared In

RKResponse.h

isSuccessful

Indicates an HTTP response code between 200 and 299.

- (BOOL)isSuccessful

Return 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.h

isUnauthorized

Indicates an HTTP response code of 401.

- (BOOL)isUnauthorized

Return Value

YES if the response is 401 Unauthorized.

Declared In

RKResponse.h

isUnprocessableEntity

Indicates an HTTP response code of 422.

- (BOOL)isUnprocessableEntity

Return Value

YES if the response is 422 Unprocessable Entity.

Declared In

RKResponse.h

isXHTML

True when the server turned an XHTML response

- (BOOL)isXHTML

Return Value

YES when the MIME type is application/xhtml+xml.

Declared In

RKResponse.h

isXML

True when the server turned an XML response

- (BOOL)isXML

Return Value

YES when the MIME type is application/xml.

Declared In

RKResponse.h

localizedStatusCodeString

Returns the localized human readable representation of the HTTP Status Code returned.

- (NSString *)localizedStatusCodeString

Declared In

RKResponse.h

location

Returns the value of the ‘Location’ HTTP Header

- (NSString *)location

Declared In

RKResponse.h

parsedBody:

Returns the response body parsed as JSON into an object

- (id)parsedBody:(NSError **)error

Parameters

error

An NSError to populate if something goes wrong while parsing the body JSON into an object.

Declared In

RKResponse.h

wasLoadedFromCache

Indicates whether the response was loaded from RKCache

- (BOOL)wasLoadedFromCache

Return Value

YES if the response was loaded from the cache

Declared In

RKResponse.h