Declared in | OCFoundation/OCFCloudApp.h |
Base class | NSObject |
Guides | Request based ApplicationsRequest based Applications in Detail |
OCFCloudApp
is a class which represents a cloud application. This class is never actually instantiated. All of its methods are class methods. By default a cloud application contains a subclass of OCFCloudApp
.
A subclass of OCFCloudApp
is called primary class, if it's name is stored in the info.plist under the key OCFCloudAppClass
.
Typically you overwrite +finishLaunching
in your subclass to get informed that the cloud application is launching. This is a good place to add routes and handlers to the cloud application using +handleRequestsWithMethod:matchingPath:withBlock:
.
Please take into account that different instances of your cloud application can run on different servers. Therefore the content of global variables can be different for two requests, because the requests can be handled by instances of cloud applications on different servers.
+finishLaunching
+additionalInformation
+handleRequestsWithMethod:matchingPath:withBlock:
+setServesStaticFiles:forBasePath:localPath:indexFilename:cacheAge:
+pushNotificationsEnabled
+defaultPushNotificationCenter
Returns additional global information.
+ (NSDictionary *)additionalInformation
This method delivers additional informations global to the cloud app. This includes database access information, if a database is booked for the cloud application. However you should use +defaultDatabaseConnection
instead of setting-up the connection yourself.
Returns the default connection of the cloud app's database.
+ (PGCConnection *)defaultDatabaseConnection
Use this method to connect to your database. If not database is booked for the cloud application, nil
is returned.
Returns the default push notification center.
+ (OCFPushNotificationCenter *)defaultPushNotificationCenter
Returns the default push notification center for the cloud app.
Finishes the launching process.
+ (void)finishLaunching
Never send this message to the receiver. It is done automatically by Objective-Cloud's runtime environment.
Typically you override this method to add routes and handlers or do other things that has to be done once after launching of your cloud app.
You cannot expect to run your cloud application continuously. It can crash or Objective-Cloud shuts it down because of high/low usage. If a new request, including invocations, is sent to your cloud application it will launch again.
Add handler for route.
+ (void)handleRequestsWithMethod:(NSString *)method
matchingPath:(NSString *)path
withBlock:(void (^) (OCFRequest *request))requestHandler
This method allows you to add routes and handlers to your cloud application. You can add as many handlers as you want to.
For each incoming request OCFCloudApp
tries to match the HTTP method and path to the list of registered handlers. If multiple routes match then the route which was added first is executed.
Using placeholders for the HTTP method is possible, but a code smell. Usually request-based services implement a RESTful service, which should map different HTTP methods to different actions.
The path can contain wildcards and variables. Variables are parts of the URL string that that are not defined by the cloud application, but set by the client. For example the path /countries/:country/
would match every path starting with /countries/
. You can read the values of the placeholders for the current request inside the handler by asking the request object passed to the handler for its parameters.
Returns YES
, if push notifications are enabled
+ (BOOL)pushNotificationsEnabled
Returns YES
, if push notifications are enabled for the cloud app, otherwise NO
.
Enables static file delivery and sets the paths for it.
+ (void)setServesStaticFiles:(BOOL)servesStaticFiles
forBasePath:(NSString *)basePath
localPath:(NSString *)localPath
indexFilename:(NSString *)indexFilename
cacheAge:(NSUInteger)cacheAge
YES
, static file delivery is turned on, otherwise off.@"/"
.nil
You can use this method to tell your cloud app to serve static files. This is especially useful if you the response if for displaying in a web browser. Web sites usually have couple of static resources (images, CSS files, JavaScript files) as elements. To prevent you from implementing a appropriate handler for each resource, OCFCloadApp
offers the ability to deliver static resources out of the box.
basePath
is the prefix that specifies the URLs for which static contents should be delivered. For example @"/resources"
as base path, a request with the path @"/resources/myphoto.jpeg"
will search for a file with the name my photo.jpeg in the services static resources directory. The path component after the basePath can include subpaths.
localPath
is the path of the the static resources folder and subfolders. Usually this is a path inside the cloud app's bundle. You can use appropriate methods of NSBundle
to get the complete path.
indexFilename
and cacheAge
are currently unsupported.