Nick Sieger: RailsConf Europe: Hydra tag:blog.nicksieger.com,2005:Typo Typo 2010-11-22T18:19:05+00:00 Tim Connor urn:uuid:3d905713-55a8-49c4-af20-68a1e0ae7d73 2007-10-16T05:35:11+00:00 2010-11-22T18:19:05+00:00 Comment on RailsConf Europe: Hydra by Tim Connor <p>I&#8217;ll have to check out those plug&#45;ins, If you like the simplicty of being able to easily edit your controller, but still keep it DRY, you can use an abstract controller, though&#46; For instance, I wrote one available at: <a href='http://code' rel="nofollow">http://code</a>&#46;google&#46;com/p/restcontroller/ ;)</p> Assaf urn:uuid:652f5113-2f29-45b2-8bdb-73440c829d6c 2007-10-08T04:24:19+00:00 2010-11-22T18:19:05+00:00 Comment on RailsConf Europe: Hydra by Assaf <p>I depends on what you&#8217;re trying to do&#46; </p> <p>If every request to the same resource returns the same data, and there are no complex transformations on the client, then the easiest solution is to change the Cache&#45;Control headers in Rails to remove &#8216;private&#8217;, and put a caching proxy between the client and server&#46;</p> <p>It saves a lot of load on the server for the few minutes it takes to setup and configure a proxy&#46; I don&#8217;t know of many applications like that&#46;</p> <p>If you handle client requests differently for the same resource &#45;&#45; say you&#8217;re using authentication and some users can see the data but others can&#8217;t &#45;&#45; then you need to specify private in Cache&#45;Control, otherwise your proxy will be leaking information to the wrong clients&#46;</p> <p>For that, you need caching in the client library, say ActiveResource or something on top of Net::HTTP&#46;</p> <p>If your client is doing complex work on the data it receives, then you don&#8217;t want to use either cache, but handle ETag/Last&#45;Modified directly&#46;</p> <p>For example, if the client reads a 10MB document only to calculate and store &#8216;total orders for the day&#8217;, then using a cache would reduce the load on the server, but you&#8217;ll still have to process 10MB of data each time you read it from the cache&#46;</p> <p>On the other hand, you can store the result along with the ETag/Last&#45;Modified headers and use conditional GET to not do any processing unless the data changed&#46;</p> Nick urn:uuid:a46f7a89-2de5-4792-ac9a-664000fcc2bc 2007-10-07T03:52:31+00:00 2010-11-22T18:19:05+00:00 Comment on RailsConf Europe: Hydra by Nick <p>Assaf: Are you saying this approach is not worth mentioning/attempting, or requires application tweaking anyway to change cache control?</p> Assaf urn:uuid:376a04ff-ea48-4a9a-85c6-75b815982b06 2007-10-06T19:54:25+00:00 2010-11-22T18:19:05+00:00 Comment on RailsConf Europe: Hydra by Assaf <p>&#8220;The great thing is that existing HTTP reverse proxies can be used without having to mix the caching code in with your application code&#46;&#8221;</p> <p>When Cache&#45;Control is private, which it is by default, it means no caching by the proxy, but the application itself can cache the data&#46;</p> Comedian urn:uuid:592efd55-445a-4527-9793-2b58a0db81ca 2007-10-06T18:07:07+00:00 2010-11-22T18:19:05+00:00 Comment on RailsConf Europe: Hydra by Comedian <p>&#8220;the HTTP method verbs HEAD, GET, POST, PUT, and DELETE&#46;&#8221;</p> <p>You&#8217;re HEADing me&#46;</p> Nick Sieger urn:uuid:d9edbea6-8e0e-43b6-af40-7d8bb3d69f52 2007-10-06T12:04:00+00:00 2010-11-22T18:19:05+00:00 RailsConf Europe: Hydra <p><img src="/files/hydra.png" alt="Hydra" title="Hydra"/></p> <p>On September 19, Craig and I presented our <a href="http://blog.nicksieger.com/articles/2007/09/14/gig-speaking-at-railsconf-europe-2007">talk at RailsConf</a>, which appears to have been <a href="http://loudthinking.com/posts/11-sun-surprises-at-railsconf-europe-2007">well received</a>&#46; It went off mostly without a hitch, if it wasn&#8217;t for a couple of hiccups in the demos&#46; I apparently didn&#8217;t practice them enough, because a couple of critical steps were either missed or I did them out of order and confused myself&#46; But that&#8217;s ok, because I&#8217;m releasing the demo steps, source and slides here so you can try them out for yourself&#46;</p> <p>So, <a href="http://blog.nicksieger.com/files/RailsConfEurope-Hydra.zip">download the zip</a> and follow along&#46; The contents look like this:</p> <pre><code>1-active-resource-basics.txt 2-make-resourceful.txt 3-atom-roller.txt 4-service-chatter.txt RailsConfEurope-Hydra.pdf demo/ demo-baked/ </code></pre> <p>The demo steps are in the text files; I&#8217;d recommend going in the order specified&#46; It turns out the third isn&#8217;t really a demo but more of a code review, because it also requires you to have Roller set up and I&#8217;m not going into those details for now&#46; If you want to just run the demos, skip to <code>demo-baked</code>, the finished product&#46;</p> <p>For those of you who didn&#8217;t see the talk, here&#8217;s the basic message&#46;</p> <p>Look at your basic MVC Rails app&#46;</p> <p><img src="/files/single.png" alt="Single app" title="Single app"/></p> <p>Why not consider spliting it into two? ActiveResource allows you to access a RESTful resource in your Rails application like it was just another model&#46;</p> <p><img src="/files/double.png" alt="Double app" title="Double app"/></p> <p>This might seem like overkill for a simple application, but what if you had an e&#45;commerce application domain like this?</p> <p><img src="/files/ecomm.png" alt="E-Commerce app" title="E-Commerce app"/></p> <p>Splitting up your code into separate Rails applications encourages encapsulation, reduces potential coupling, and gives you more flexible deployment options&#46; Basing interactions upon REST and HTTP means that you can more easily mash up data or create caching strategies, given proper usage of ETags/Last&#45;Modified and/or cache&#45;control headers&#46; The great thing is that existing HTTP reverse proxies can be used without having to mix the caching code in with your application code&#46;</p> <p>In the application we&#8217;re building, we have a number components that are not Rails&#45;based&#46; To expose them to our environment, we&#8217;ve taken the strategy of exposing a simple REST web service for the component, and then it can be consumed by the other applications using ActiveResource&#46; The REST web service can either be implemented in the component&#8217;s native language/technology, or in some cases we&#8217;ve written a wrapper service in Rails since Rails makes it so easy to build REST interfaces&#46; In that case, Rails is pure integration &#45;&#45; RESTful glue&#46;</p> <p>The idiom that makes this all possible is the uniform interface&#46; In HTTP, this means addressability (each resource gets a unique URI) coupled with the HTTP method verbs HEAD, GET, POST, PUT, and DELETE&#46; Inside your Rails applications, it&#8217;s the ActiveRecord interface&#46; If you <a href="http://www.therailsway.com/2007/6/1/railsconf-recap-skinny-controllers">keep your controllers skinny</a>, you can boil the interface down to the following set of methods (in this case, for the prototypical blog post model):</p> <pre><code>Post.new/Post.create Post.find @post.save @post.update_attributes @post.errors @post.destroy </code></pre> <p>And in fact, this is precisely what ActiveResource provides, and it&#8217;s enabled by <a href="http://en.wikipedia.org/wiki/Duck_typing">duck&#45;typing</a>&#46; Walking through the demos illustrates this pretty well, as you&#8217;ll basically swap ActiveRecord for ActiveResource with no noticeable difference, all the way down to validation errors in the scaffolded forms (which I was unable to demo in the talk due to the hiccups)&#46;</p> <p>We&#8217;ve found that when you&#8217;re making RESTful web services, the controllers largely become boilerplate because of the uniform interface&#46; <a href="http://svn.hamptoncatlin.com/make_resourceful/trunk/"><code>make_resourceful</code></a> has been a boon in that regard, as the demos also show&#46; There are several plugins that help you DRY up your controllers (other approaches include <a href="http://plugins.ardes.com/doc/resources_controller/"><code>resources_controller</code></a>), so you have some choices there&#46;</p> <p>We mentioned some drawbacks in our experience with ActiveResource, which have largely been addressed for the upcoming Rails 2&#46;0 release&#46;</p> <p>Finally, we noted that deployment could be a pain with so many Rails applications to keep running&#46; To that end, we are leveraging JRuby and Glassfish to make this a non&#45;issue, as we simply WAR up our Rails applications with <a href="http://blog.nicksieger.com/articles/2007/09/04/warbler-a-little-birdie-to-introduce-your-rails-app-to-java">warbler</a> and let Glassfish take care of the rest&#46; Performance is still an open question, but we plan to roll up our sleeves and make sure this combination really hums&#46;</p> <p>Enjoy the demos! Feel free to drop me an email if you have any questions or troubles with them&#46;</p>