Packageorg.restfulx
Classpublic class Rx

Provides central access to a number of frequently used subsystems, configuration options and helpers.

Commonly used and most important subsystems to be aware of are:

A number of static helper functions also live in this namespace including:

See also

org.restfulx.controllers.ModelsController
org.restfulx.controllers.ServicesController
org.restfulx.controllers.CommandsController
org.restfulx.controllers.SerializersController
org.restfulx.controllers.ChangeController
org.restfulx.controllers.UndoRedoController


Public Properties
 PropertyDefined by
  airDatabaseName : String = "rxdb"
[static] Default database name to use for AIR applications.
Rx
  airEnableDatabaseMigrations : Boolean = false
[static] Any properties that you add to your models can be automatically added to your AIR database.
Rx
  airEncryptionKey : ByteArray
[static] Encryption key to use for connection to AIR SQLite database (if this field is empty connection will be unencrypted = default).
Rx
  authenticityToken : String
[static] Stores current authenticity token.
Rx
  changes : ChangeController
[static] exposes the Synchronization capable controller
Rx
  commands : CommandsController
[static] auxiliary (typically non-CRUD) commands controller
Rx
  couchDbDatabaseName : String = "rxdb"
[static] Default database name to use for apps talking to CouchDB directly.
Rx
  couchDbRootUrl : String = "http://127.0.0.1:5984/"
[static] Root URL for CouchDB requests.
Rx
  customHttpHeaders : Array
[static] Stores any extra HTTP headers that needs to be sent to the backend
Rx
  defaultMetadata : Object
[static] Metadata allows us to tag arbitrary data along with any provider requests this is typically useful with HTTP provider (but may be useful with other providers too).
Rx
  defaultServiceId : int
[static] default service provider to use.
Rx
  enableSync : Boolean = false
[static] If set to true, synchronization controller will be initialized
Rx
  enableUndoRedo : Boolean = false
[static] If set to true, undo/redo for create(), update() and destroy() is enabled.
Rx
  httpController : Class
[static] default http controller implementation to use
Rx
  httpControllerHandler : Function
[static] If http controller handler function is set, it allows you to override behaviour of the send() function in httpController.
Rx
  httpRootUrl : String = "/"
[static] default root URL for HTTP requests, gets prefixed to CRUD and AUX HTTP operations
Rx
  log : ILogger
[static] Framework logger.
Rx
  models : ModelsController
[static] centralized access to RESTful CRUD operations on models
Rx
  serializers : SerializersController
[static] exposes commonly used serializers (XML and VO)
Rx
  services : ServicesController
[static] exposes currently registered service providers
Rx
  sessionToken : String
[static] Stores current session id for use by URLRequest.
Rx
  undoredo : UndoRedoController
[static] exposes the undo-redo capable controller
Rx
  undoRedoStackSize : int = 10
[static] Control the size of the undo-redo stack.
Rx
Public Methods
 MethodDefined by
  
Rx(enforcer:PrivateEnforcer)
Rx
  
amf(optsOrOnResult:Object = null, onFault:Function = null, contentType:String = "application/x-www-form-urlencoded", resultFormat:String = "binary", serializer:ISerializer = null, rootUrl:String = null):AuxHTTPController
[static] Handy shortcut for non-CRUD AMF operations.
Rx
  
[static] Enables tracing for internal restfulx framework classes.
Rx
  
filter(items:ArrayCollection, filter:Function = null):RxCollection
[static] Filters a given RxCollection with no side effects, a new restfulx array collection is created that the filter is applied on.
Rx
  
filter$(items:RxCollection, filter:Function = null):RxCollection
[static] Filters a given RxCollection in place, this version actually modifies the instance passed in as the argument.
Rx
  
filters(items:RxCollection, filters:Array = null):RxCollection
[static] Applies a composite filter to a given RxCollection with no side effects, a new restfulx array collection is created that the filters are applied on.
Rx
  
filters$(items:RxCollection, filters:Array = null):RxCollection
[static] Applies a composite filter to a given RxCollection in place, this version actually modifies the instance passed in as the argument.
Rx
  
http(optsOrOnResult:Object = null, onFault:Function = null, contentType:String = "application/x-www-form-urlencoded", resultFormat:String = "text", serializer:ISerializer = null, rootUrl:String = null):AuxHTTPController
[static] Handy shortcut for non-CRUD HTTP operations.
Rx
  
merge(items:ArrayCollection, toAdd:Array, after:Boolean = false):RxCollection
[static] Merges an array into a RxCollection (without side-effects).
Rx
  
reset():void
[static] Clears errors, defaultMetadata and the sessionToken (a half-harted attempt at cleaning up framework state, a bullet-proof way, which also clears event listeners you may have is to reload the app on logout.)
Rx
  
sort(items:RxCollection, fields:Array = null):RxCollection
[static] Sorts a given RxCollection using SortFields (or anonymous objects) provided without side effects.
Rx
  
sort$(items:RxCollection, fields:Array = null):RxCollection
[static] Sorts a given RxCollection using SortFields (or anonymous objects) provided in place.
Rx
Public Constants
 ConstantDefined by
  DEFAULT_ERROR_FIELD : String = ":base"
[static] default error namespace used by service providers
Rx
Property detail
airDatabaseNameproperty
public static var airDatabaseName:String = "rxdb"

Default database name to use for AIR applications. Simply set Rx.airDatabaseName anywhere in your code to override. This is usually done at application initialization.


Example
     Rx.airDatabaseName = "myairdb";
     

airEnableDatabaseMigrationsproperty 
public static var airEnableDatabaseMigrations:Boolean = false

Any properties that you add to your models can be automatically added to your AIR database. Set this variable to true if you want to enable this functionality.

NOTE: Given limitations in SQLite we can only add columns, existing columns will not be renamed or removed as you add/remove/rename properties in your models. It is your responsibility to migrate data and cleanup client databases if required.

airEncryptionKeyproperty 
public static var airEncryptionKey:ByteArray

Encryption key to use for connection to AIR SQLite database (if this field is empty connection will be unencrypted = default).

authenticityTokenproperty 
public static var authenticityToken:String

Stores current authenticity token.

changesproperty 
public static var changes:ChangeController

exposes the Synchronization capable controller

commandsproperty 
public static var commands:CommandsController

auxiliary (typically non-CRUD) commands controller

couchDbDatabaseNameproperty 
public static var couchDbDatabaseName:String = "rxdb"

Default database name to use for apps talking to CouchDB directly. Simply set Rx.couchDbdatabaseName anywhere in your code to override. This is usually done at application initialization.


Example
     Rx.couchDbDatabaseName = "foobar";
     

couchDbRootUrlproperty 
public static var couchDbRootUrl:String = "http://127.0.0.1:5984/"

Root URL for CouchDB requests.


Example
http://127.0.0.1:5984/

customHttpHeadersproperty 
public static var customHttpHeaders:Array

Stores any extra HTTP headers that needs to be sent to the backend

defaultMetadataproperty 
public static var defaultMetadata:Object

Metadata allows us to tag arbitrary data along with any provider requests this is typically useful with HTTP provider (but may be useful with other providers too).

Default metadata specifies metadata that always gets sent along. You can always provide metadata on a per-ModelsController CRUD method basis.
Example
Default metadata is typically an anonymous object

      Rx.defaultMetadata = {foo: 'bar', bar: 'foo'};
     

defaultServiceIdproperty 
public static var defaultServiceId:int

default service provider to use. XMLHTTPServiceProvider.ID is default.

enableSyncproperty 
public static var enableSync:Boolean = false

If set to true, synchronization controller will be initialized

enableUndoRedoproperty 
public static var enableUndoRedo:Boolean = false

If set to true, undo/redo for create(), update() and destroy() is enabled.

httpControllerproperty 
public static var httpController:Class

default http controller implementation to use

httpControllerHandlerproperty 
public static var httpControllerHandler:Function

If http controller handler function is set, it allows you to override behaviour of the send() function in httpController.


Example
Here's one approach:
      public override function send(url:String, data:Object = null, method:int = AuxHTTPController.GET,
        responder:IResponder = null):void {
              var response:Object = null;
         if (Rx.httpControllerHandler != null) {
           response = Rx.httpControllerHandler(this, url, data, method);
         }  
              responder.result(new ResultEvent(ResultEvent.RESULT, false, false, response));   
      }
     

httpRootUrlproperty 
public static var httpRootUrl:String = "/"

default root URL for HTTP requests, gets prefixed to CRUD and AUX HTTP operations

logproperty 
public static var log:ILogger

Framework logger. In order to see any framework-level logging at all you should call Rx.enableLogging() anywhere in your code. This is typically done at application initialization.

You can control log level by passing appropriate argument to Rx.enableLogging(), such as LogEventLevel.INFO

See also

modelsproperty 
public static var models:ModelsController

centralized access to RESTful CRUD operations on models

serializersproperty 
public static var serializers:SerializersController

exposes commonly used serializers (XML and VO)

servicesproperty 
public static var services:ServicesController

exposes currently registered service providers

sessionTokenproperty 
public static var sessionToken:String

Stores current session id for use by URLRequest. If your application requires authentication, it is recommended that you return a session token from the server as a result of login. This session token will be re-used for subsequent calls until the user logs out. This is particularly important for file uploads.

undoredoproperty 
public static var undoredo:UndoRedoController

exposes the undo-redo capable controller

undoRedoStackSizeproperty 
public static var undoRedoStackSize:int = 10

Control the size of the undo-redo stack. the default is 10 (undo redo must be enabled with Rx.enableUndoRedo = true) before this will have any effect

Constructor detail
Rx()constructor
public function Rx(enforcer:PrivateEnforcer)Parameters
enforcer:PrivateEnforcer
Method detail
amf()method
public static function amf(optsOrOnResult:Object = null, onFault:Function = null, contentType:String = "application/x-www-form-urlencoded", resultFormat:String = "binary", serializer:ISerializer = null, rootUrl:String = null):AuxHTTPController

Handy shortcut for non-CRUD AMF operations. Works in much the same way as Rx.http except it expects to receive AMF serializes messages as response

Parameters
optsOrOnResult:Object (default = null) — can be either an anonymous object of options or a result handler function. Many functions in the framework can be called with named params specified in an object or explicitly in the order required by the function. See the example above.
 
onFault:Function (default = null) — function to call on URLLoader error
 
contentType:String (default = "application/x-www-form-urlencoded") — content type for the request
 
resultFormat:String (default = "binary") — how to treat the response from the server (binary is the default)
 
serializer:ISerializer (default = null) — ISerializer implementation to use when unmarshalling responses. Use this in conjunction with resultFormat. Default is AMFSerializer.
 
rootUrl:String (default = null) — the URL to prefix to requests

Returns
AuxHTTPController — AuxHTTPController instance

See also


Example
It can be used to send any object to any URL by doing something like this:
      Rx.amf(function(result:Object):void { trace(result); }).invoke("some/url/here");
     

This will send a GET request with no arguments to "some/url/here" and call anonymous function provided when the result comes back.

enableLogging()method 
public static function enableLogging():void

Enables tracing for internal restfulx framework classes. This is useful for debugging purposes. The log can be seen in the console of Flex Builder when you are ebugging as opposed to running your project.

filter()method 
public static function filter(items:ArrayCollection, filter:Function = null):RxCollection

Filters a given RxCollection with no side effects, a new restfulx array collection is created that the filter is applied on.

Parameters
items:ArrayCollection — ArrayCollection instance to filter
 
filter:Function (default = null) — filter function

Returns
RxCollection — new filtered RxCollection instance
filter$()method 
public static function filter$(items:RxCollection, filter:Function = null):RxCollection

Filters a given RxCollection in place, this version actually modifies the instance passed in as the argument.

Parameters
items:RxCollection — ArrayCollection to filter (will be motified in place)
 
filter:Function (default = null) — filter function

Returns
RxCollection — original array collection with the filter applied
filters()method 
public static function filters(items:RxCollection, filters:Array = null):RxCollection

Applies a composite filter to a given RxCollection with no side effects, a new restfulx array collection is created that the filters are applied on.

Parameters
items:RxCollection — RxCollection instance to filter
 
filters:Array (default = null) — an Array of filter functions

Returns
RxCollection — new filtered RxCollection instance
filters$()method 
public static function filters$(items:RxCollection, filters:Array = null):RxCollection

Applies a composite filter to a given RxCollection in place, this version actually modifies the instance passed in as the argument.

Parameters
items:RxCollection — RxCollection to filter (will be motified in place)
 
filters:Array (default = null) — an Array of filter functions to apply

Returns
RxCollection — original array collection with the filters applied
http()method 
public static function http(optsOrOnResult:Object = null, onFault:Function = null, contentType:String = "application/x-www-form-urlencoded", resultFormat:String = "text", serializer:ISerializer = null, rootUrl:String = null):AuxHTTPController

Handy shortcut for non-CRUD HTTP operations.

Parameters
optsOrOnResult:Object (default = null) — can be either an anonymous object of options or a result handler function. Many functions in the framework can be called with named params specified in an object or explicitly in the order required by the function. See the example above.
 
onFault:Function (default = null) — function to call on HTTPService error
 
contentType:String (default = "application/x-www-form-urlencoded") — content type for the request
 
resultFormat:String (default = "text") — how to treat the response from the server (text is the default)
 
serializer:ISerializer (default = null) — ISerializer implementation to use when unmarshalling responses. Use this in conjunction with resultFormat. Default is XMLSerializer.
 
rootUrl:String (default = null) — the URL to prefix to requests

Returns
AuxHTTPController — AuxHTTPController instance

See also


Example
It can be used to send any object to any URL by doing something like this:
      Rx.http(function(result:Object):void { trace(result); }).invoke("some/url/here");
     

This will send a GET request with no arguments to "some/url/here" and call anonymous function provided when the result comes back.

Or
     Rx.http({
      resultHandler: someFunctionToHandleResult,
      faultHandler: someFunctionToHandleFault,
      contentType: "application/xml"
     }).invoke({data: bla, method: "POST", unmarshall: true});
     

merge()method 
public static function merge(items:ArrayCollection, toAdd:Array, after:Boolean = false):RxCollection

Merges an array into a RxCollection (without side-effects). A new RxCollection is created/returned as a result.

Parameters
items:ArrayCollection — ArrayCollection to merge into
 
toAdd:Array — Array to merge
 
after:Boolean (default = false) — if true toAdd gets appended else prepended

Returns
RxCollection — a ewRxCollection
reset()method 
public static function reset():void

Clears errors, defaultMetadata and the sessionToken (a half-harted attempt at cleaning up framework state, a bullet-proof way, which also clears event listeners you may have is to reload the app on logout.)

sort()method 
public static function sort(items:RxCollection, fields:Array = null):RxCollection

Sorts a given RxCollection using SortFields (or anonymous objects) provided without side effects. A new sorted collection is returned.

Parameters
items:RxCollection — RxCollection to sort (will be not motified in place)
 
fields:Array (default = null) — an Array of SortFields or anonymous objects that represent SortFields

Returns
RxCollection — new array collection with the sorts applied
sort$()method 
public static function sort$(items:RxCollection, fields:Array = null):RxCollection

Sorts a given RxCollection using SortFields (or anonymous objects) provided in place.

Parameters
items:RxCollection — RxCollection to sort (will be motified in place)
 
fields:Array (default = null) — an Array of SortFields or anonymous objects that represent SortFields

Returns
RxCollection — original array collection with the sorts applied
Constant detail
DEFAULT_ERROR_FIELDconstant
public static const DEFAULT_ERROR_FIELD:String = ":base"

default error namespace used by service providers