ActionScript and JSON Idea
I just had a new idea. Or, at least it's new to me. The idea is a framework for a Rich Internet Application (RIA) that allows a Flex-based RIA to communicate with a server-based database using a RESTful JSON communication channel.
The thing that makes this idea different is that the server would not just use JSON to serialize the data, but would actually embed methods into the object with ActionScript code that implements a full ActiveRecord or ActiveResource pattern for the object being retrieved.
So, in the RIA client we could have some code like this:
var prod:Product = Product.Create();
prod.name = "my product";
prod.Save();
So, on line one we have a factory method that creates a new Product object by calling the http://server/product/create rest method and getting back a block of ActionScript code that it can Eval() into an object. This product object then has properties that can be read or written and methods for saving the data. The Save() method on line three actually fires off an http request to the server to save that specific record in the database - http://server/product/save/42 where 42 is the primary key value for this object.
The great thing is that the server side code generator and REST API should then be completely generic across all RIAs. All the custom application logic is in the RIA, not the server. The server is only responsible for authentication/membership and data persistence.
