Would You Like XML With That?
Feb 21st, 2007 by phil
Jamis Buck says in a post at The Rails Way that it is “trivial…to make your application into a web-service. There’s really very little reason not to do it.” I can think of one very good reason not to turn every controller into a web service: if you don’t need web services then that is just more code that you have to test.
I have been working with ReSTful controllers in my own Rails apps for a couple of months now and I like the new features. At first I thought “wow, I get all this cool XML stuff for free!”, but it soon became clear I would never need to use it. Seriously, if you are going to leave the generated XML support in your controllers you need to test it. If you don’t need it and don’t want to test it, take it out.
PS: I should mention that both The Rails Way and Jamis’ blog have lots of great Rails content. Both are highly recommended.





A good point, Phillip. However, given the benefits of allowing your app to be consumable as a web service, and how little code it really requires to test these web services, I still maintain that you might as well do it as not. Still, YMMV, and obviously not every action of every controller will makes sense to expose as a web service.
NOTE: The following comment from “Rashun M” made it far enough through the system that it was emailed to me, but typo barfed and it never got saved to the database. I have reproduced the comment in full.
Rahsun M said 2 days later:
I’ve been working with REST since the simply_restful. It has other benefits “obviously” then the free APIs.
I love the clean easy to read and maintainable structure. I can jump in and out different apps and pass them along to another REST-FUL minded individual and they can be in there coding in no time.
After a while I came to the same conclusion. If you don’t need to take advantage of XML, or Javascript, or whatever else - don’t put it in there.
However, it’s nice to know that if I need to flip the API switch, it can be done SUPER EASY!