Developing Flex Applications on Google App Engine with RestfulX

lyle edited this page Aug 14, 2010 · 4 revisions

This is yet another installment of the standard RestfulX framework tutorial. This time we are going to cover development and deployment of RestfulX-based Flex applications on the Google Application Engine.

For the other tutorials in this series check out:

  1. Getting Started with RestfulX and Ruby On Rails
  2. Developing Standalone AIR Applications using RestfulX
  3. Using CouchDB in Flex/AIR with RestfulX

All of these tutorials share the same data model. We create a little task management application called pomodo each and every time to keep context-switching overhead small. One other thing you might notice is that your generated ActionScript3/MXML code is actually the same in all of these cases. Of course, in a fully featured application different approaches and techniques will soon emerge. You might implement log-in, search or image handling funtionality different for example. However, the fundamental CRUD functionality, more often then not, stays the same. Why re-invent the wheel?

First the usual disclaimer :)

While it’s possible to write the entire Application by hand, you can use a few handy generators that come with restfulx gem to help you get up and running faster. Ruby is a great language to for code generation. We use it to create a basic Rakefile and add a few RubiGen based generators to help you along the way. It is possible to open/edit any of these projects in Flex Builder 3 if you want to. In fact, when you use rx-gen generator project files for Flex Builder 3 and TextMate are created by default.

What you’ll need:

  1. Flex SDK 3.0 +
  2. Google App Engine SDK for your platform
  3. Python (something that’ll work with Google App Engine SDK, refer to GAE docs for details)
  4. Ruby 1.8.6 + (for code generation, not required to use/run the application)

Before you start you might want to add Flex SDK bin folder to your $PATH variable if you haven’t already. This will allow you to invoke commands such as mxmlc from the command line and run rake tasks such as restfulx:flex:build.

  • On OS X it’s typically /Applications/Adobe Flex Builder 3/sdks/3.0.0/bin
  • On Win32 it’s C:\Program Files\Adobe\Flex Builder 3\sdks\3.0.0\bin

Let’s begin

First, let’s create a project:


$>sudo gem install restfulx
$>rx-gen --gae pomodo
$>cd pomodo

Notice the flag --gae. What this does is create a few GAE specific configuration options. To see all available options use rx-gen -h.

Then run:


$>./script/generate rx_config

Then create a file called db/model.yml:


$>touch db/model.yml

Edit db/model.yml to contain the following:


project:
 - name: string
 - notes: text
 - start_date: date
 - end_date: date
 - completed: boolean
 - belongs_to: [user]
 - has_many: [tasks]

location:
 - name: string
 - notes: text
 - belongs_to: [user]
 - has_many: [tasks]

task:
 - name: string
 - notes: text
 - start_time: datetime
 - end_time: datetime
 - completed: boolean
 - next_action: boolean
 - belongs_to: [project, location, user]

note:
 - content: text
 - belongs_to: [user]

user:
 - login: string
 - first_name: string
 - last_name: string
 - email: string
 - has_many: [tasks, projects, locations]
 - has_one: [note]

Now we can generate the app:


$>./script/generate rx_yaml_scaffold --gae

Again, notice the flag --gae. What this does is make sure that the generator also generates our Python code for running on Google Application Engine and interfacing with the Google Data Store.

Now let’s build the Flex application:


$>rake rx:flex:build

You are done!

To run the app open it up in your GoogleAppEngineLauncher and start. Use File > Add Existing Application to locate your pomodo folder on the filesystem and bring it into the Launcher app. If you want to deploy the application make sure your app.yaml file is correct and you own that name on the appspot.com server.

To see the list of all available tasks type:


$>rake -T

While code generation is a quick way to get started, it falls far short of exposing you to all the things you can do with the framework. Examine the code you just generated and refer to Working with RestfulX Models for more information on what you can accomplish.

If you have any questions get in touch at RestfulX Framework Google Group

For more information on the RestfulX Framework refer to Home

Want a more feature complete example? Check out Pomodo On GAE