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.
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
|
protected function addHeaders(request:URLRequest, headers:Object):voidParameters
| request:URLRequest |
| |
| headers:Object |
protected function defaultFaultHandler(info:Object, token:Object = null):voidParameters
| info:Object |
| |
| token:Object (default = null) |
protected function defaultResultHandler(data:Object, token:Object = null):voidParameters
| data:Object |
| |
| token:Object (default = null) |
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:
|
| |
| httpHeaders:* (default = null) — an object (key, value pairs) of HTTP headers to send along with this request
|
protected function marshallToURLVariables(source:Object):URLVariablesParameters
Returns
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.
protected function unmarshall(data:Object):ObjectParameters
Returns
protected function unmarshallAndCacheResultHandler(data:Object, token:Object = null):voidParameters
| data:Object |
| |
| token:Object (default = null) |
protected function unmarshallResultHandler(data:Object, token:Object = null):voidParameters
| data:Object |
| |
| token:Object (default = null) |
public static const DELETE:int = 4
public static const GET:int = 1
public static const POST:int = 2
public static const PUT:int = 3