Packageorg.restfulx.controllers
Classpublic class AuxHTTPController
InheritanceAuxHTTPController Inheritance flash.events.EventDispatcher
SubclassesMockAuxHTTPController

Custom HTTP controller that allows sending arbitrary data (as opposed to models) over HTTP faking PUT and DELETE. You can use this to perform any non-CRUD actions including the ability to treat responses as-if there were CRUD actions. This is useful on many levels.


Example
This will produce a GET request to "some/url", where "some/url" can be mapped to any server-side controller action:
   Rx.http(function(result:Object):void { 
   // do whatever you want with the result object here 
   }).invoke("some/url");
    
   // or something like this:
    
    var invokeOpts:Object = { URL: "sessions.fxml", method: "POST", data: 
       {email: "foobar-at-foobar.com", password: "bla"}, 
      unmarshall: true, cacheBy: "show"};
    
   // and then:
   Rx.http(onSuccessfulLogin, onBadLogin).invoke(invokeOpts); 
   

onSuccessfulLogin is a handler function for successful result, onBadLogin is a handler function for failure. The line above can be pretty much used with something like RESTful authentication to login a user.

If you know that your custom method returns a known model instance you can choose to unmarshall it and/or cache it simulating one of:

These are in fact the options to cacheBy parameter of invoke function.

See also

invoke


Public Methods
 MethodDefined by
  
AuxHTTPController(optsOrOnResult:Object = null, onFault:Function = null, contentType:String = "application/x-www-form-urlencoded", resultFormat:String = "text", serializer:ISerializer = null, rootUrl:String = null)
AuxHTTPController
  
invoke(optsOrURL:Object, data:Object = null, method:Boolean, unmarshall:String = "false", cacheBy:Object = null, httpHeaders:* = null):void
Invokes a specified URL using indicated method and passing provided data.
AuxHTTPController
  
send(url:String, data:Object = null, method:int, responder:IResponder = null, httpHeaders:Object = null):void
A different take on invoke.
AuxHTTPController
Protected Methods
 MethodDefined by
  
addHeaders(request:URLRequest, headers:Object):void
AuxHTTPController
  
defaultFaultHandler(info:Object, token:Object = null):void
AuxHTTPController
  
defaultResultHandler(data:Object, token:Object = null):void
AuxHTTPController
  
marshallToURLVariables(source:Object):URLVariables
AuxHTTPController
  
unmarshall(data:Object):Object
AuxHTTPController
  
unmarshallAndCacheResultHandler(data:Object, token:Object = null):void
AuxHTTPController
  
unmarshallResultHandler(data:Object, token:Object = null):void
AuxHTTPController
Public Constants
 ConstantDefined by
  DELETE : int = 4
[static]
AuxHTTPController
  GET : int = 1
[static]
AuxHTTPController
  POST : int = 2
[static]
AuxHTTPController
  PUT : int = 3
[static]
AuxHTTPController
Constructor detail
AuxHTTPController()constructor
public function AuxHTTPController(optsOrOnResult:Object = null, onFault:Function = null, contentType:String = "application/x-www-form-urlencoded", resultFormat:String = "text", serializer:ISerializer = null, rootUrl:String = null)

Parameters
optsOrOnResult:Object (default = null) — can be either an anonymous object of options or a result handler function.
 
onFault:Function (default = null) — function to call on URLLoader error or if unmarshalling fails
 
contentType:String (default = "application/x-www-form-urlencoded") — content type for the request
 
resultFormat:String (default = "text") — what to treat the response as (e.g. text, binary)
 
serializer:ISerializer (default = null) — what serializer to use (default is XML)
 
rootUrl:String (default = null) — the URL to prefix to requests
Method detail
addHeaders()method
protected function addHeaders(request:URLRequest, headers:Object):voidParameters
request:URLRequest
 
headers:Object
defaultFaultHandler()method 
protected function defaultFaultHandler(info:Object, token:Object = null):voidParameters
info:Object
 
token:Object (default = null)
defaultResultHandler()method 
protected function defaultResultHandler(data:Object, token:Object = null):voidParameters
data:Object
 
token:Object (default = null)
invoke()method 
public function invoke(optsOrURL:Object, data:Object = null, method:Boolean, unmarshall:String = "false", cacheBy:Object = null, httpHeaders:* = null):void

Invokes a specified URL using indicated method and passing provided data. Optionally unmarshalling and/or caching the response.

Parameters
optsOrURL:Object — can be either an anonymous object of options or a result handler function.
 
data:Object (default = null) — data object to pass along
 
method:Boolean — HTTP method to use (one of GET, PUT, POST or DELETE)
 
unmarshall:String (default = "false") — boolean indicating if the response should be unmarshalled using HTTPSericeProvider
 
cacheBy:Object (default = null) — a String describing recommended caching method for this response. If you specify cacheBy unmarshalling is performed automatically, using specified serializer. Possible options are:
  • index
  • show
  • update
  • create
 
httpHeaders:* (default = null) — an object (key, value pairs) of HTTP headers to send along with this request
marshallToURLVariables()method 
protected function marshallToURLVariables(source:Object):URLVariablesParameters
source:Object

Returns
URLVariables
send()method 
public function send(url:String, data:Object = null, method:int, responder:IResponder = null, httpHeaders:Object = null):void

A different take on invoke. Can be used with standalone org.restfulx.controllers.ICommand implementations if they also implement IResponder interface.

Parameters
url:String — URL to call
 
data:Object (default = null) — data to pass along
 
method:int — method to use
 
responder:IResponder (default = null) — IResponder implementation to callback.
 
httpHeaders:Object (default = null) — an object (key, value pairs) of HTTP headers to send along with this request

See also


Example
If you don't like to create responder objects you can use ItemResponder like so:
     controller.send("/foobar.xml", {some:"data"}, SimpleHTTPController.GET,
       new ItemResponder(function result(data:Object):void {},
        function fault(info:Object):void {});
     

Or use invoke function above.

unmarshall()method 
protected function unmarshall(data:Object):ObjectParameters
data:Object

Returns
Object
unmarshallAndCacheResultHandler()method 
protected function unmarshallAndCacheResultHandler(data:Object, token:Object = null):voidParameters
data:Object
 
token:Object (default = null)
unmarshallResultHandler()method 
protected function unmarshallResultHandler(data:Object, token:Object = null):voidParameters
data:Object
 
token:Object (default = null)
Constant detail
DELETEconstant
public static const DELETE:int = 4
GETconstant 
public static const GET:int = 1
POSTconstant 
public static const POST:int = 2
PUTconstant 
public static const PUT:int = 3