Matt Garland (8) [Avatar] Offline
#1
Hi,

After I finished Pomodo, I got all ambitious and started architecting a Flex Rails chat site with some social-networking features. Right now I'm pretty cloudy about how to organize my RESTy services, however. It's not just that I'm new to REST--being a pure Actionscripter until I read this book, I'm new to the business layer.

First off, REST sounds great to me. I really like the idea of creating a simple API for accessing data like a folder hierarchy ("user/14") and I especially like the routing options, which hide any extra logic necessary ("project/19/users").

The problems start with the social-networking features that involve some data that is more complex than "user/14". For instance, once a user is logged into a chat room, they need various kinds of texts (table: notes) that in-room (table: activeChatters) friends (table: friends) have chosen to share with the user (table friends, column: sharesNotes).

The chapter on RubyAMF shows various delegate classes calling CRUD operations off remote objects. But how would you approximate (in a remoting method) the WebServices url "project/19/users" or anything more complex than CRUD? Without, that is, ending up with some mess where complex logic must mirror each other on both the client and the rails app--which would muddy the whole point of REST. More generally, are routing options excluded when we use remoting?

I watched some of the recommended REST articles and videos and I understand that 1) routing should never go beyond a second layer because it gets too confusing. I also understand that more models are better than more logic. So perhaps I could create a table like activeChatterersSharedResources, which would be updated as users logged on and off, and could be directly queried, REST-style.

But before I go off in that direction I wanted to get straight about some basic business layer stuff. What exactly is an "object graph"? I'm inferring that, if you create table associations in Rails, when you pull one object out, you pull its associated objects, too. Is this something automatic, and applying equally to web services and remoting? Or is this a matter of un-automagically building an elaborate VO that nests a bunch of other VOs? (I'm guessing that, in the Rails app, I could pull up the graph, then easily reference the associations, cut the data up and transfer it to VOs, which I then aggregate into a mega-VO?)

Also, let's say I took the most direct approach possible. The user enters a room, checks to see if any friends are there, checks to see what his privileges are with them, then retrieves the various friends data one at a time. This would be a bunch of sequential calls, ending in a bunch of multiple calls. This would be RESTy. But, except for discrete calls themselves, which would be totally clear, hard to read, and--as far as I understand--not very efficient in terms of remoting. (My understanding being that one big call is faster than a bunch of little calls.) Am I wrong here, or is there a better way of being RESTy than I am describing?

Lastly, one way of remaining RESTy would be to just grab oodles of data from Rails and let Flex sort it out. (Grabbing ALL the resouces of ALL the users in the chat, then making only some of it available--I'm not worried about security, for reasons hard to explain here). I'm not planning more than minimal animation or graphics, nor any stretchy layouts, so I'm hoping the processor will be fresh and available. Is this smelly? And in general, I'm confused about where to allocate work when I have a choice--Rails or Flex? Because I'm comfortable with Actionscript, and worried about Rails performance, I'd lean towards Flex, but that seems arbitrary.

Hope this is not too vague. My first steps beyond Pomodo have been more complicated than I though they would be, perhaps because I'm not making a straight-up RIA, if there is such a thing. I'm just looking around wondering what the best practices are.
Matt Garland (8) [Avatar] Offline
#2
Re: REST architecture and RubyAMF
So that was a bit wordy maybe. Here are the specific questions:

1) Can routing be used in conjunction with remoting?
2) How do you retrieve an "object graph" for a VO?
3) Are many small remoting calls better than one big call?

Thanks!
peterarmstrong (94) [Avatar] Offline
#3
Re: REST architecture and RubyAMF
Hi Matt,

Regarding object graphs: without sounding too much like a commercial, take a look at the Ruboss framework (and Enterprise Flexible Rails) for what I consider to be the best way to do Flex + Rails development. It takes the Flexible Rails approach and runs with it, and helps with unmarshalling objects and hooking up object graphs etc. The Ruboss framework is the foundation of my company, which is currently 4 developers doing Flex and Rails development...

Regarding routing and remoting, I don't have the best answer right now -- we're focused on XML over HTTPService (and AIR) currently...

Cheers,
Peter
Matt Garland (8) [Avatar] Offline
#4
Re: REST architecture and RubyAMF
Hi Peter,

I took a quick look at Ruboss, but need more info--there's more specifics in your short post (object graphs, marshalling) than in the documentation about how or why Flex/Ruby integration takes place.

I have to admit Restfullness is taking a bit more hassle and discipline than I expected. I keep thinking to myself "I want a very specific, very complex object at a certain point in the client--why not just write the verySpecificVeryComplex method on a remoting service?"

For now I'm sticking with Restfulness, however. As I spitball it, spinning out more interrelated models (tables like inChatSharedNotes) seems easier than I thought. And complex objects demand complex parsing and logic on both sides, which seems brittle and hard to read. As for optimizing, I have no idea what the reality is, so I might as well focus on what makes the app easier to program, for now.

Look forward to Ruboss,

Matt
T-1000 (1) [Avatar] Offline
#5
Re: REST architecture and RubyAMF
Hey Matt,

I got your comment on my blog. I wrote up a brief tutorial for Ruboss. And I've been thinking a lot about how to build a social networking site RESTfully too. Check out Insoshi if you haven't already, it's a great starting point. In the next few months I would like to create a social networking site for scientists using Flex on Rails, maybe we could help each other out along the way.

Ruboss is insanely powerful indeed. Ultimately, I imagine that if everything is built RESTfully with Ruboss, we will have "social software components" that are completely reusable, repeatable, interactive, and customizable, and we can start moving away from things like Wordpress and Facebook and start allowing the world to build bigger, better, and more interactive ones as a team. I had a chance to talk with Doug Engelbart on Tuesday and he was talking about the future of the internet...

Eye glasses that read information wirelessly from your cell phone to present information, like seeing what you think. I think the interactivity of Flash and the simplicity of RESTful Rails will make it feel like you are mapping your thoughts right in front of you into the real world. Thanks to Ruboss, this vision is even closer. We still have a few years of inventing til that happens though smilie

Peace,
Lance
Matt Garland (8) [Avatar] Offline
#6
Re: REST architecture and RubyAMF
cool lance, thanks--here's the link for others:

http://www.systemsofseven.com/blog/make/23