NSRRequest Class Reference
| Inherits from | NSObject |
| Conforms to | NSCoding |
| Declared in | NSRRequest.h |
Overview
NSRRequest is a class used internally by NSRRemoteObject to make remoteX requests, but can also be used directly to construct custom resource paths, etc.
The methods in this class are set up so that making requests is concise and visually logical:
//GET to /posts/1
id response = [[[NSRRequest GET] routeToObject:post] sendSynchronous:&e];
//PATCH to /posts/1 with post as body
NSRRequest *request = [NSRRequest PATCH];
[request routeToObject:post];
[request setBodyToObject:post];
id response = [request sendSynchronous:&e];
Factory methods also exist (used by NSRRemoteObject) if you’d like to make only an incremental change to an existing request:
NSRRequest *request = [NSRRequest requestToFetchAllObjectsOfClass:[Post class]];
request.queryParameters = @{@"q":@"search"};
//GET to /posts?q=search
id response = [request sendSynchronous:&e];
Tasks
Properties
-
configConfig used to make the request.
property -
routeThe path to be appended to config’s rootURL (the base URL of your app).
property -
httpMethodThe HTTP verb with which to make the request.
property -
queryParametersThe query parameters with which to make the request.
property -
additionalHTTPHeadersA dictionary of additional HTTP headers to send with the request.
property -
bodyRequest body.
property
Creating an NSRRequest by HTTP method
-
+ GETCreates and returns an NSRRequest object initialized with
httpMethodset to@"GET". -
+ DELETECreates and returns an NSRRequest object initialized with
httpMethodset to@"DELETE". -
+ POSTCreates and returns an NSRRequest object initialized with
httpMethodset to@"POST". -
+ PUTCreates and returns an NSRRequest object initialized with
httpMethodset to@"PUT". -
+ PATCHCreates and returns an NSRRequest object initialized with
httpMethodset to@"PATCH".
Creating an NSRRequest by function
-
+ requestToFetchObjectWithID:ofClass:Creates and returns an NSRRequest object set to fetch an object with a specified ID.
-
+ requestToFetchAllObjectsOfClass:Creates and returns an NSRRequest object set to fetch all objects of a given class.
-
+ requestToFetchAllObjectsOfClass:viaObject:Creates and returns an NSRRequest object set to fetch all objects of a given class given a parent object.
-
+ requestToCreateObject:Creates and returns an NSRRequest object set to remotely create a given object.
-
+ requestToFetchObject:Creates and returns an NSRRequest object set to fetch a given object’s remote correspondance.
-
+ requestToDestroyObject:Creates and returns an NSRRequest object set to remotely destroy a given object.
-
+ requestToUpdateObject:Creates and returns an NSRRequest object set to remotely update a given object.
-
+ requestToReplaceObject:Creates and returns an NSRRequest object set to remotely “put” (replace) a given object.
Routing a request
-
– routeTo:Routes the request to the given string.
-
– routeToClass:Routes the request to a given class’s controller.
-
– routeToObject:Routes the request to a given object.
-
– routeToClass:withCustomMethod:Routes the request to a given class’s controller.
-
– routeToObject:withCustomMethod:Routes the request to a given object.
Setting the request body
-
– setBodyToObject:Sets the body to a given object.
Sending the request
-
– sendSynchronous:Sends the request synchronously.
-
– sendAsynchronous:Sends the request asynchronously.
Properties
additionalHTTPHeaders
A dictionary of additional HTTP headers to send with the request.
@property (nonatomic, strong) NSDictionary *additionalHTTPHeadersDeclared In
NSRRequest.hbody
Request body.
@property (nonatomic, strong) id bodyDiscussion
Must be a JSON-parsable object (NSArray, NSDictionary, NSString) or will throw an exception.
Declared In
NSRRequest.hconfig
Config used to make the request.
@property (nonatomic, strong) NSRConfig *configDiscussion
This property is automatically set when a routeTo method is invoked (will set it to the config of the class/instance).
Will use NSRConfig’s defaultConfig by default (ie, is not routed to an object or class).
When this request is made, any additionalHTTPHeaders defined for this config are added to the request header (along with this instance’s own additionalHTTPHeaders).
Declared In
NSRRequest.hhttpMethod
The HTTP verb with which to make the request.
@property (nonatomic, readonly) NSString *httpMethodDeclared In
NSRRequest.hqueryParameters
The query parameters with which to make the request.
@property (nonatomic, strong) NSDictionary *queryParametersDiscussion
NSRRequest *request = [[NSRRequest GET] routeTo:@"something"];
request.queryParameters = @{@"q":@"search"};
//GET to /something?q=search
id response = [request sendSynchronous:&e];
Warning: Doesn’t escape anything! Make sure your params are RFC 1808 compliant.
Declared In
NSRRequest.hroute
The path to be appended to config’s rootURL (the base URL of your app).
@property (nonatomic, readonly) NSString *routeDiscussion
You cannot set this variable directly - use the routeTo methods below.
Declared In
NSRRequest.hClass Methods
DELETE
Creates and returns an NSRRequest object initialized with httpMethod set to @"DELETE".
+ (NSRRequest *)DELETEReturn Value
An NSRRequest object initialized with httpMethod set to @"DELETE".
Declared In
NSRRequest.hGET
Creates and returns an NSRRequest object initialized with httpMethod set to @"GET".
+ (NSRRequest *)GETReturn Value
An NSRRequest object initialized with httpMethod set to @"GET".
Declared In
NSRRequest.hPATCH
Creates and returns an NSRRequest object initialized with httpMethod set to @"PATCH".
+ (NSRRequest *)PATCHReturn Value
An NSRRequest object initialized with httpMethod set to @"PATCH".
Declared In
NSRRequest.hPOST
Creates and returns an NSRRequest object initialized with httpMethod set to @"POST".
+ (NSRRequest *)POSTReturn Value
An NSRRequest object initialized with httpMethod set to @"POST".
Declared In
NSRRequest.hPUT
Creates and returns an NSRRequest object initialized with httpMethod set to @"PUT".
+ (NSRRequest *)PUTReturn Value
An NSRRequest object initialized with httpMethod set to @"PUT".
Declared In
NSRRequest.hrequestToCreateObject:
Creates and returns an NSRRequest object set to remotely create a given object.
+ (NSRRequest *)requestToCreateObject:(NSRRemoteObject *)objParameters
- obj
Object you wish to create.
Return Value
An NSRRequest object set to remotely create a given object.
Discussion
POST request routed to the given object (ID is ignored).
POST /posts
Or, if NSRRemoteObject’s objectUsedToPrefixRequest: is overriden and returns a non-nil object,
POST /users/3/posts
Declared In
NSRRequest.hrequestToDestroyObject:
Creates and returns an NSRRequest object set to remotely destroy a given object.
+ (NSRRequest *)requestToDestroyObject:(NSRRemoteObject *)objParameters
- obj
Object you wish to fetch.
Return Value
An NSRRequest object set to destroy a given object’s remote correspondance.
Discussion
DELETE request routed to the given object.
DELETE /posts/1
Or, if NSRRemoteObject’s objectUsedToPrefixRequest: is overriden and returns a non-nil object,
DELETE /users/3/posts/1
Declared In
NSRRequest.hrequestToFetchAllObjectsOfClass:
Creates and returns an NSRRequest object set to fetch all objects of a given class.
+ (NSRRequest *)requestToFetchAllObjectsOfClass:(Class)classParameters
- class
Class of the object you wish to fetch. Must be an NSRRemoteObject subclass.
Return Value
An NSRRequest object set to fetch all objects of a given class.
Discussion
GET request routed to the given class.
GET /posts
Declared In
NSRRequest.hrequestToFetchAllObjectsOfClass:viaObject:
Creates and returns an NSRRequest object set to fetch all objects of a given class given a parent object.
+ (NSRRequest *)requestToFetchAllObjectsOfClass:(Class)class viaObject:(NSRRemoteObject *)objParameters
- class
Class of the object you wish to fetch. Must be an NSRRemoteObject subclass.
- obj
Parent object used to prefix the route.
Return Value
An NSRRequest object set to fetch all objects of a given class given a parent object.
Discussion
GET request routed to the given parent object, the custom method being the class’s index page.
GET /users/3/posts
Declared In
NSRRequest.hrequestToFetchObject:
Creates and returns an NSRRequest object set to fetch a given object’s remote correspondance.
+ (NSRRequest *)requestToFetchObject:(NSRRemoteObject *)objParameters
- obj
Object you wish to fetch.
Return Value
An NSRRequest object set to fetch a given object’s remote correspondance.
Discussion
GET request routed to the given object.
GET /posts/1
Or, if NSRRemoteObject’s objectUsedToPrefixRequest: is overriden and returns a non-nil object,
GET /users/3/posts/1
Declared In
NSRRequest.hrequestToFetchObjectWithID:ofClass:
Creates and returns an NSRRequest object set to fetch an object with a specified ID.
+ (NSRRequest *)requestToFetchObjectWithID:(NSNumber *)remoteID ofClass:(Class)classParameters
- remoteID
Remote ID of the object you wish to fetch. Will raise an exception if this is
nil.
- class
Class of the object you wish to fetch. Must be an NSRRemoteObject subclass.
Return Value
An NSRRequest object set to fetch an object with a specified ID.
Discussion
GET request routed to the given class, the custom method being the remoteID.
GET /posts/1
Declared In
NSRRequest.hrequestToReplaceObject:
Creates and returns an NSRRequest object set to remotely “put” (replace) a given object.
+ (NSRRequest *)requestToReplaceObject:(NSRRemoteObject *)objParameters
- obj
Object you wish to update.
Return Value
An NSRRequest object set to remotely “put” (replace) a given object.
Discussion
PUT request routed to the given object.
PUT /posts/1
Or, if NSRRemoteObject’s objectUsedToPrefixRequest: is overriden and returns a non-nil object,
PUT /users/3/posts/1
Declared In
NSRRequest.hrequestToUpdateObject:
Creates and returns an NSRRequest object set to remotely update a given object.
+ (NSRRequest *)requestToUpdateObject:(NSRRemoteObject *)objParameters
- obj
Object you wish to update.
Return Value
An NSRRequest object set to remotely update a given object.
Discussion
Request routed to the given object. HTTP method depends on config’s updateMethod.
(PUT, PATCH, etc) /posts/1
Or, if NSRRemoteObject’s objectUsedToPrefixRequest: is overriden and returns a non-nil object,
(PUT, PATCH, etc) /users/3/posts/1
Declared In
NSRRequest.hInstance Methods
routeTo:
Routes the request to the given string.
- (NSRRequest *)routeTo:(NSString *)routeParameters
- route
The route.
Declared In
NSRRequest.hrouteToClass:
Routes the request to a given class’s controller.
- (NSRRequest *)routeToClass:(Class)classParameters
- class
Class to which to route. Must be an NSRRemoteObject subclass.
Declared In
NSRRequest.hrouteToClass:withCustomMethod:
Routes the request to a given class’s controller.
- (NSRRequest *)routeToClass:(Class)class withCustomMethod:(NSString *)customMethodParameters
- class
Class to route to. Must be an NSRRemoteObject subclass.
- customMethod
Custom method to be appended to the class’s controller RESTfully (can be
nil.)
Declared In
NSRRequest.hrouteToObject:
Routes the request to a given object.
- (NSRRequest *)routeToObject:(NSRRemoteObject *)objectParameters
- object
Object to route to. If this object’s
remoteIDisnil, will only route to its class.
Declared In
NSRRequest.hrouteToObject:withCustomMethod:
Routes the request to a given object.
- (NSRRequest *)routeToObject:(NSRRemoteObject *)object withCustomMethod:(NSString *)customMethodParameters
- object
Object to route to. If this object’s
remoteIDisnil, will only route to its class.
- customMethod
Custom method to be appended RESTfully (can be
nil.)
Return Value
The request itself. Done to allow concise constructions (see above).
Declared In
NSRRequest.hsendAsynchronous:
Sends the request asynchronously.
- (void)sendAsynchronous:(NSRHTTPCompletionBlock)completionBlockParameters
- completionBlock
Block to be executed when the request is complete.
Discussion
Handles Rails errors, as well as basic connection errors.
Declared In
NSRRequest.hsendSynchronous:
Sends the request synchronously.
- (id)sendSynchronous:(NSError **)errorParameters
- error
Out parameter used if an error occurs while processing the request. May be
NULL, but please check for errors.
Return Value
JSON response object.
Discussion
Handles Rails errors, as well as basic connection errors.
Declared In
NSRRequest.hsetBodyToObject:
Sets the body to a given object.
- (void)setBodyToObject:(NSRRemoteObject *)objectParameters
- object
Object to use as a body to send the request.
Discussion
Will convert the object into a JSON-parsable object (an NSDictionary) by calling NSRRemoteObject’s remoteDictionaryRepresentationWrapped: on it.
Declared In
NSRRequest.h