Saturday, October 20, 2007

RESTful Development

Along with Named Routes comes RESTful development. So what is RESTful development? Well, I'm not even going to try to define here. A very uesful link is the RestWiki, which talks about what REST is.

I must say that I quite agree with this architectural style. I can see how it really tries to create uniform interfaces so that different applications are able to communicate with each other. Especially over the World Wide Web, as they say, RESTful development is almost natural. However, I think we have been developing so long without REST that it will be awkward at first to get use to.

RoR, along with Named Routes, supports RESTful development quite well. Each controller, because it represents a model, will have a Named Route corresponding to it. Furthermore, this restricts the controller to having only 7 actions. Yes, that's correct. I said 7!

index
show
new
create
edit
update
destroy

This seems very limiting, but when we're dealing with 1 particular resource, these 7 actions are, in fact, quite sufficient. There may be 1 or 2 extra actions that may need to be customized, but usually, these will be all you need!

With REST, it is easy for other applications to easily hook into yours. With RoR, it is easy to return different formats to the caller, such as XML. A really nice explanation can be found here:

http://softiesonrails.com/tags/rest

Well, have fun poking around REST. Hopefully, this will convince you to try it out for yourselves as well!

W

No comments: