Hi, I just wrote an article on how to easily create a REST API for Ruby on Rails applications: http://www.xml.com/pub/a/2006/04/19/rest-on-rails.html It describes how to create everything from the ground up and includes information on testing your API too. -- Thanks, Dan Kubb
Dan Kubb wrote:> Hi, > > I just wrote an article on how to easily create a REST API for > Ruby on Rails applications: > > http://www.xml.com/pub/a/2006/04/19/rest-on-rails.html > > It describes how to create everything from the ground up and includes > information on testing your API too. > > -- > > Thanks, > > Dan KubbRock solid stuff, did the whole thing. Especially awesome for Code to Test Ratio: 1:2.7 which for a tutorial is the most tests I have seen. One critique is I think it could use a bit of info about REST. I didn''t know much about REST before this, so I wasn''t sure why I was doing these things. Maybe just a paragraph about the principals and how it uses the request types and stuff. -- Posted via http://www.ruby-forum.com/.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hi Alex,>> I just wrote an article on how to easily create a REST API for >> Ruby on Rails applications: >> >> http://www.xml.com/pub/a/2006/04/19/rest-on-rails.html > > Rock solid stuff, did the whole thing. Especially awesome for Code to > Test Ratio: 1:2.7 which for a tutorial is the most tests I have seen.Thank you. I wanted to provide a set of test cases for a simple application so that I could enhance it in further articles, adding conditional GET support and supporting HTML and JSON in addition to XML. I haven''t written it yet, but I think I can do it with maybe 5 to 10 lines of controller code, and maybe a dozen or so lines of view and test code.> One critique is I think it could use a bit of info about REST. I > didn''t > know much about REST before this, so I wasn''t sure why I was doing > these > things. Maybe just a paragraph about the principals and how it > uses the > request types and stuff.To tell you the truth when I saw the article I was disappointed that the part where I gave real world examples of why REST architecture is important was edited out. IMHO the article is a little weak without it -- people need to be told the *why* behind something before being told the *what*. Ah well, it was my favorite part of the article so I''m posting it here anyway ;) Let me know what you think:>> Breaking Convention >> >> When the Google Web Accelerator was released in 2005 it >> illustrates a perfect example where going against the grain will >> cause problems for developers. The Google Web Accelerator is a >> plugin for web browsers that prefetches all the links on a page >> and caches the responses on google''s servers. If you later click >> on the same link the new page may load more quickly since its >> already been downloaded and cached. >> >> The problem was that many applications were designed so that >> hyperlinks are used to change state on the server. That means >> that its possible to delete information or cancel processes by >> clicking on a link and using a GET request. When the Google Web >> Accelerator follows those state changing links it causes >> information to be lost or changed without the user''s knowledge. >> >> Rather than examining their approach to see if they''ve >> contributed to the problem, many people were quick to blame >> Google for the loss of information in their applications. The >> thing about GET requests is that they should be safe and be free >> from side effects. There''s a part of the HTTP specification that >> says GET requests should only be used to retrieve information, >> not change it. Google designed their application around the >> specifications and some developers chose to ignore the >> specifications, either intentionally or ignorantly. >> >> I''m not going to argue that I think the Google Web Accelerator >> itself is a good idea, but I do think its safe to say there will >> be more applications like it in the future. Even today one of the >> most popular plugins for Firefox is a prefetching plugin called >> FasterFox. I wouldn''t be surprised if automatic link prefetching >> became a standard feature in mainstream browsers someday because >> from the user''s point of view the browser with prefetching would >> out-perform those without it. >> >> Its not just prefetching we should be thinking about. In the >> future there will be applications that rely on other parts of the >> HTTP specification that we haven''t even dreamt of. If you''re >> building web applications that go against HTTP in some way you >> could be at risk for future problems like the ones with the >> Google Web Accelerator. Rather than becoming angry maybe there is >> a way to learn from this and eliminate similar problems before >> they ever happen.This would''ve appeared immediately between the second and third paragraphs of the article. Its a little rough, but I think it makes the point a little better.. - -- Thanks, Dan __________________________________________________________________ Dan Kubb Autopilot Marketing Inc. Email: dan.kubb@autopilotmarketing.com Phone: 1 (604) 820-0212 Web: http://autopilotmarketing.com/ vCard: http://autopilotmarketing.com/~dan.kubb/vcard __________________________________________________________________ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2.2 (Darwin) iD8DBQFESdZt4DfZD7OEWk0RAormAJoCDzXsNBvxdwC9VrD15Qq6OABTggCfTmaf LQiyipOr41IhGlb2WDspZ0I=gRS5 -----END PGP SIGNATURE-----
Dan Kubb wrote:> -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Hi Alex, > >>> I just wrote an article on how to easily create a REST API for >>> Ruby on Rails applications: >>> >>> http://www.xml.com/pub/a/2006/04/19/rest-on-rails.html >> >> >> Rock solid stuff, did the whole thing. Especially awesome for Code to >> Test Ratio: 1:2.7 which for a tutorial is the most tests I have seen. > > > Thank you. I wanted to provide a set of test cases for a simple > application so that I could enhance it in further articles, adding > conditional GET support and supporting HTML and JSON in addition > to XML. I haven''t written it yet, but I think I can do it with > maybe 5 to 10 lines of controller code, and maybe a dozen or so > lines of view and test code. > >> One critique is I think it could use a bit of info about REST. I >> didn''t >> know much about REST before this, so I wasn''t sure why I was doing >> these >> things. Maybe just a paragraph about the principals and how it uses >> the >> request types and stuff. > > > To tell you the truth when I saw the article I was disappointed that > the part where I gave real world examples of why REST architecture is > important was edited out. IMHO the article is a little weak without > it -- people need to be told the *why* behind something before being > told the *what*. > > Ah well, it was my favorite part of the article so I''m posting it > here anyway ;) Let me know what you think: > >>> Breaking Convention >>> >>> When the Google Web Accelerator was released in 2005 it >>> illustrates a perfect example where going against the grain will >>> cause problems for developers. The Google Web Accelerator is a >>> plugin for web browsers that prefetches all the links on a page >>> and caches the responses on google''s servers. If you later click >>> on the same link the new page may load more quickly since its >>> already been downloaded and cached. >>> >>> The problem was that many applications were designed so that >>> hyperlinks are used to change state on the server. That means >>> that its possible to delete information or cancel processes by >>> clicking on a link and using a GET request. When the Google Web >>> Accelerator follows those state changing links it causes >>> information to be lost or changed without the user''s knowledge. >>> >>> Rather than examining their approach to see if they''ve >>> contributed to the problem, many people were quick to blame >>> Google for the loss of information in their applications. The >>> thing about GET requests is that they should be safe and be free >>> from side effects. There''s a part of the HTTP specification that >>> says GET requests should only be used to retrieve information, >>> not change it. Google designed their application around the >>> specifications and some developers chose to ignore the >>> specifications, either intentionally or ignorantly. >>> >>> I''m not going to argue that I think the Google Web Accelerator >>> itself is a good idea, but I do think its safe to say there will >>> be more applications like it in the future. Even today one of the >>> most popular plugins for Firefox is a prefetching plugin called >>> FasterFox. I wouldn''t be surprised if automatic link prefetching >>> became a standard feature in mainstream browsers someday because >>> from the user''s point of view the browser with prefetching would >>> out-perform those without it. >>> >>> Its not just prefetching we should be thinking about. In the >>> future there will be applications that rely on other parts of the >>> HTTP specification that we haven''t even dreamt of. If you''re >>> building web applications that go against HTTP in some way you >>> could be at risk for future problems like the ones with the >>> Google Web Accelerator. Rather than becoming angry maybe there is >>> a way to learn from this and eliminate similar problems before >>> they ever happen. >> > > This would''ve appeared immediately between the second and third > paragraphs of the article. Its a little rough, but I think it > makes the point a little better.. > > - -- > > Thanks, > > Dan > __________________________________________________________________ > > Dan Kubb > Autopilot Marketing Inc. > > Email: dan.kubb@autopilotmarketing.com > Phone: 1 (604) 820-0212 > Web: http://autopilotmarketing.com/ > vCard: http://autopilotmarketing.com/~dan.kubb/vcard > __________________________________________________________________ > > > > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.2.2 (Darwin) > > iD8DBQFESdZt4DfZD7OEWk0RAormAJoCDzXsNBvxdwC9VrD15Qq6OABTggCfTmaf > LQiyipOr41IhGlb2WDspZ0I> =gRS5 > -----END PGP SIGNATURE----- > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Is all the code provided? -- Berlin Brown (ramaza3 on freenode) http://www.newspiritcompany.com http://www.newspiritcompany.com/newforums also checkout alpha version of botverse: http://www.newspiritcompany.com:8086/universe_home