Using REST with Flex and Force.com

Here’s a video on the other half of the library showed in the previous entry on OAuth, this time detailing how can use the library to use the REST API for Force.com.  If you use OAuth and REST, you can use this library as a standalone way to work with Force.com, or you can mix and match it with the existing SOAP based Flex and AIR toolkit.  There’s still some complications when using it for with Flash For Force.com build, or more specifically using the application wrapper and query functions there rely on it’s own login functionality to access the database (though the SOAP toolkit is available within that build).

An example of using the OAuth login and then performing a REST based query looks like this:

private function login():void {
rest = new RESTConnection();
rest.oauthConnection = new OAuthConnection("{PUBLICKEY}","{PRIVATEKEY}","{CALLBACK}");
rest.oauthConnection.login(this.stage,new mx.rpc.AsyncResponder(loginHandler,com.force.utility.util.genericError));
}
private function loginHandler(loginResult:Object, token:Object):void {
rest.oauth = loginResult;
rest.query("SELECT ID, Name from Contact LIMIT 5",new mx.rpc.AsyncResponder(queryHandler,com.force.utility.util.genericError));
}


The REST library will also attempt to auto-refresh the token handling, allowing you to keep the user logged in until “OAuthConnection.clearAccess()” is invoked.  More examples can be found in the readme file, and you can also browse a TestProject and alpha code updates at my github account.

Feel free to catch me via email (joshua.birk @ salesforce.com) or twitter with questions, comments and requests.  I’d say grab some popcorn and enjoy the video below, but at seven minutes long … you’ll have a lot of popcorn left…

 

Published
May 18, 2011
Topics:

Leave your comments...

Using REST with Flex and Force.com