Objective-C in the Cloud

OCFRequest Class Reference

Declared inOCFoundation/OCFResponse.h
Base classNSObject
GuidesRequest based Applications
Request based Applications in Detail


An instance of OCFRequest represents an HTTP request. Instance objects of OCFRequest and not created by your cloud application, but provided by the Objective-Cloud runtime environment when a request for your application is received. To a request-based service the object is passed as an argument of the handler. Inside an invocation-based service the request object is a property of the current invocation object that can be retrieved with +currentInvocation.

You usually use the provided instance object to introspect the the content of the request and send a response to it. Running a request-based service you have to do this manually. For invocation-based services this is done by the runtime environment automatically for arguments and return values. But there are still reasons to deal with instance objects of OCFRequest manually, especially if you want to read additional information from the request or want to respond in a non-JSON format (i. e. HTML.) However, using the request object in an invocation-based service extensively is a code smell.

You can respond to a request with an instance object of OCFResponse or for convenience with instance objects of NSString, NSDictionary, or OCFMustache respectively as described for -respondWith:.



- respondWith:


@parameters @userBadges

Declared Properties


The content length.

@property (nonatomic, assign, readonly) NSUInteger contentLength

This property holds the content length of the request.


The content type.

@property (nonatomic, copy, readonly) NSString *contentType

This property holds the content type of the request. This is a computed property for convenience which should be equivalent to headers[@"Content-Type"].


The cookies.

@property (copy, readonly) NSArray *cookies


The cookies contained in the request contains as instances of NSHTTPCookie..


The body.

@property (nonatomic, copy, readwrite) NSData *data


The HTTP body of the request as an instance object of NSData.


The header fields.

@property (nonatomic, copy, readonly) NSDictionary *headers


The header fields of the request.


The host part of the URL.

@property (readonly) NSString *host


The host part of the request's URL#p_URL) that means of the host that has been requested.

The string does not contain the port. Objective-Cloud uses the default port for HTTPS (443) and locally the Port 10000 for HTTP.


The HTTP method.

@property (nonatomic, copy, readonly) NSString *method


This property holds the HTTP method used in the request, i. e. GET, POST, PUT, or DELETE)

        <td>Returns the path of the requested resource. </td>


The HTTP method.

@property (nonatomic, copy, readonly) NSString *method


This property holds the HTTP method used in the request, i. e. GET, POST, PUT, or DELETE)


The path of the request.

@property (nonatomic, copy, readonly) NSDictionary *parameters


A property holding the parameters of the HTTP request.

Parameters can be many things: For example if your route contains a placeholders like /path/:id/:action then the parameters dictionary contain the keys and values for the placeholders.


The path of the request.

@property (nonatomic, copy, readonly) NSString *path


The path used in the request.


The query of the URL.

@property (nonatomic, copy, readonly) NSDictionary *query


Returns the query of the URL as a dictionary according to RFC 1801.


The URL.

@property (nonatomic, copy, readonly) NSURL *URL


The URL used in the request.


The content length.

@property (nonatomic, strong, readonly) NSMutableDictionary userBadges

You can use the dictionary to store your own information related to the request. Keys starting with com.objective-cloud are reserved for internal use.

Instance Methods


Sends a respond to the request.

- (void)respondWith:(id)response


The response value.


This method is used to pass a response back to the client. After responding the request is closed and you cannot send additional data (one-shot).

The response argument can be an instance object of the following classes:

  • OCFResponse: A fully configurable response object.
  • NSString: A string used as the body of the response. The header is automatically set.
  • NSDictionary: A dictionary with the response data as described below.
  • OCFMustache: A mustache instance object.

If you choose a dictionary response you can set three key-value pairs:

  • status: An NSNumber object containing the HTTP response status.
  • headers: A dictionary with key-value pairs for the header fields.
  • body: An instance object of NSData containing the response body.

A typical dictionary response looks like this:

// Responding with the application icon
NSImage *image = [NSImage imageNamed:@"NSApplicationIcon"];
[request respondWith:@{ @"status" : @201,
                        @"body" : [image TIFFRepresentation],
                        @"headers" : @{ @"Content-Type" : @"image/tiff" }}];