<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jabbering Giraffe &#187; rest</title>
	<atom:link href="http://happygiraffe.net/blog/tag/rest/feed/" rel="self" type="application/rss+xml" />
	<link>http://happygiraffe.net/blog</link>
	<description></description>
	<lastBuildDate>Tue, 07 Feb 2012 20:49:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>REST Web Services in Java</title>
		<link>http://happygiraffe.net/blog/2008/09/13/rest-web-services-in-java/</link>
		<comments>http://happygiraffe.net/blog/2008/09/13/rest-web-services-in-java/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 21:43:43 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1383</guid>
		<description><![CDATA[I&#8217;ve been taking a look at jersey today. It&#8217;s an implementation of JSR 311, which is a proposed spec for implementing REST-like web services in Java. I started with the tutorial, which is quite frankly pretty bloody simple. @Path&#40;&#34;/helloworld&#34;&#41; public &#8230; <a href="http://happygiraffe.net/blog/2008/09/13/rest-web-services-in-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been taking a look at <a href="https://jersey.dev.java.net/">jersey</a> today.  It&#8217;s an implementation of <a href="https://jsr311.dev.java.net/">JSR 311</a>, which is a proposed spec for implementing REST-like web services in Java.  I started with the <a href="https://jersey.dev.java.net/use/getting-started.html">tutorial</a>, which is quite frankly pretty bloody simple.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  @Path<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/helloworld&quot;</span><span style="color: #009900;">&#41;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloWorldResource <span style="color: #009900;">&#123;</span>
    @GET
    @Produces<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> getClichedMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #0000ff;">&quot;Hello World&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>The javadoc for the annotations explains what they do in some more detail (<a href="https://jsr311.dev.java.net/nonav/releases/0.9/javax/ws/rs/Path.html">Path</a>, <a href="https://jsr311.dev.java.net/nonav/releases/0.9/javax/ws/rs/GET.html">GET</a>, <a href="https://jsr311.dev.java.net/nonav/releases/0.9/javax/ws/rs/Produces.html">Produces</a>).</p>
<p>The tutorial also includes a method of running that standalone using the <a href="https://grizzly.dev.java.net/">grizzly HTTP connector</a>.  But I&#8217;m a stick-in-the-mud.  I want it to run under <a href="http://tomcat.apache.org/tomcat-6.0-doc/index.html">tomcat</a>.  So how do I do that?  Again, it turns out to be fairly simple.  Just add the jersey-supplied integration servlet to your <code>web.xml</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dispatcher<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.spi.container.servlet.ServletContainer<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun.jersey.config.property.packages<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>net.happygiraffe.jerseytest<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/param-value<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/init-param<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/load-on-startup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dispatcher<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>I specified an extra parameter to say which package I want scanned for resources.  Otherwise Jersey will scan everything in <code>/WEB-INF/classes</code> and <code>/WEB-INF/lib</code> by default.  Anyway, this works a treat:</p>
<pre>
% curl -i http://localhost:8080/jerseytest/hello
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: text/plain
Transfer-Encoding: chunked
Date: Sat, 13 Sep 2008 20:44:41 GMT

hello world
</pre>
<p>I&#8217;m going to play with this some more.  The API feels quite nice.  Particularly when compared to <a href="http://www.restlet.org/">Restlets</a>, which I found a little bit <em>too</em> uniform.  Mind you, the <a href="http://blog.noelios.com/2008/04/01/restlet-11-m3-released/">latest restlet code has its own version of JSR 311 support</a>, so it may still be useful.  It&#8217;s also actually worth checking out the <a href="https://jsr311.dev.java.net/drafts/spec20080827.pdf">JSR-311 spec</a>, as it&#8217;s quite readable.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/09/13/rest-web-services-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>REST on RAILS</title>
		<link>http://happygiraffe.net/blog/2005/11/03/rest-on-rails/</link>
		<comments>http://happygiraffe.net/blog/2005/11/03/rest-on-rails/#comments</comments>
		<pubDate>Thu, 03 Nov 2005 20:29:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cdbi]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2005/11/03/rest-on-rails/</guid>
		<description><![CDATA[Matt Biddulph has just had an article published on xml.com, REST on rails. It&#8217;s a really great way of working, and I encourage closer scrutiny. And it shows off Rails at its best. I really look forward to playing with &#8230; <a href="http://happygiraffe.net/blog/2005/11/03/rest-on-rails/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Matt Biddulph has just had an article published on xml.com, <a href="http://www.xml.com/pub/a/2005/11/02/rest-on-rails.html"><span class="caps">REST</span> on rails</a>.  It&#8217;s a really great way of working, and I encourage closer scrutiny.   And it shows off Rails at its best.  I really look forward to playing with Rails more.  I would like to implement <span class="caps">PUT</span> for that rest_resource method as well&#8230;</p>
<p>It also happens to be very similar to a system I wrote at work a couple of years ago using <a href="http://www.perl.org/">Perl</a> and <a href="http://search.cpan.org/dist/Class-DBI/">Class::DBI</a>.  The system we have at work is a bit more complicated and has more edge cases in the generated <span class="caps">XML</span>, particularly with regards to nesting.  Looking at that article makes me wonder if we couldn&#8217;t simplify the design our protocol&#8230;  But it&#8217;s already in use by so many clients, I think that would be difficult at this point.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2005/11/03/rest-on-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Broken web sites still broken</title>
		<link>http://happygiraffe.net/blog/2005/10/25/broken-web-sites-still-broken/</link>
		<comments>http://happygiraffe.net/blog/2005/10/25/broken-web-sites-still-broken/#comments</comments>
		<pubDate>Tue, 25 Oct 2005 08:07:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2005/10/25/broken-web-sites-still-broken/</guid>
		<description><![CDATA[The Google Web Accelerator has just been brought back, apparently. I don&#8217;t care much, except to note that it&#8217;s caused the rails people to go, well, off the rails. Again. I don&#8217;t really have much to add to the discussion, &#8230; <a href="http://happygiraffe.net/blog/2005/10/25/broken-web-sites-still-broken/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://webaccelerator.google.com/">Google Web Accelerator</a> has just been brought back, apparently. I don&#8217;t care much, except to note that it&#8217;s caused the rails people to go, well, <em><a href="http://37signals.com/svn/archives2/the_google_web_accelerator_is_back_with_a_vengeance.php">off the rails</a></em>.  Again.</p>
<p>I don&#8217;t really have much to add to the discussion, except to point at Aristotle&#8217;s <a href="http://plasmasturm.org/log/347/">choice extracts</a>.  In a sense this is all quite amusing, except for the fact that the rails people still don&#8217;t grok what they&#8217;re getting wrong.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2005/10/25/broken-web-sites-still-broken/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why we need REST</title>
		<link>http://happygiraffe.net/blog/2005/05/09/why-we-need-rest/</link>
		<comments>http://happygiraffe.net/blog/2005/05/09/why-we-need-rest/#comments</comments>
		<pubDate>Mon, 09 May 2005 08:00:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2005/05/09/why-we-need-rest/</guid>
		<description><![CDATA[There&#8217;s a neat new toy from google&#8212;the Google Web Accelerator (GWA). It uses Googles cache to serve up web pages quickly, but it also apparently does link prefetching. This is good for the most part, as it speeds things up &#8230; <a href="http://happygiraffe.net/blog/2005/05/09/why-we-need-rest/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a neat new toy from google&#8212;the <a href="http://webaccelerator.google.com/">Google Web Accelerator</a> (GWA).  It uses Googles cache to serve up web pages quickly, but it also apparently does <a href="http://www.mozilla.org/projects/netlib/Link_Prefetching_FAQ.html">link prefetching</a>.  This is good for the most part, as it speeds things up a lot.</p>
<p>The difference between <span class="caps">GWA</span> and Mozilla is that <span class="caps">GWA</span> pre-fetches every single link on the page if it doesn&#8217;t find a <code>&amp;lt;link rel="next"&amp;gt;</code> on that page.</p>
<p>This combines with the fact that some people have <a href="http://37signals.com/svn/archives2/google_web_accelerator_hey_not_so_fast_an_alert_for_web_app_designers.php">links to &#8220;delete&#8221; and &#8220;cancel&#8221;</a> on their web sites.</p>
<p>Now, the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616.html"><span class="caps">HTTP</span> spec</a> says that if you <span class="caps">GET</span> a page, then that must cause no change on the server side (<a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.1">safe</a>).  By creating a link that deletes something, you are breaking the rules.</p>
<p>Of course, if browsers supported <span class="caps">HTTP</span> a bit better, then they&#8217;d use a <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.7"><span class="caps">DELETE</span></a> verb for such an action.  But even without that, you can still use a form and <span class="caps">POST</span> for non safe actions.  It&#8217;s definitely worth bearing in mind next time you&#8217;re writing a web app.</p>
<p><ins datetime="2005-4-9T10:58:40--1:00"><strong>Update</strong>: <a href="http://community.moertel.com/ss/comments/start/2005-05-08/1">Tom Mortoel</a> has described the problem better than I have.  And also offered actual code for a solution, which helps.  Also note the informative comments.</ins></p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2005/05/09/why-we-need-rest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails and REST</title>
		<link>http://happygiraffe.net/blog/2005/04/28/ruby-on-rails-and-rest/</link>
		<comments>http://happygiraffe.net/blog/2005/04/28/ruby-on-rails-and-rest/#comments</comments>
		<pubDate>Thu, 28 Apr 2005 19:01:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2005/04/28/ruby-on-rails-and-rest/</guid>
		<description><![CDATA[I&#8217;ve spent a little while over the last few days looking at Ruby on Rails. It seems to live up to the claims of its proponents. You can develop applications very quickly indeed, and it&#8217;s easy to get a good &#8230; <a href="http://happygiraffe.net/blog/2005/04/28/ruby-on-rails-and-rest/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent a little while over the last few days looking at <a href="http://www.rubyonrails.org/">Ruby on Rails</a>.  It seems to live up to the claims of its proponents.  You can develop applications very quickly indeed, and it&#8217;s easy to get a good separation of concerns. If you haven&#8217;t played with it before, have a look at the <span class="caps">TODO</span> list examples: <a href="http://manuals.rubyonrails.com/read/book/7">Making a todo list</a> and <a href="http://www.rubyonrails.com/media/text/Rails4Days.pdf">Four Days on Rails</a>.  Overall, I&#8217;m really, really impressed.</p>
<p>I do have one gripe through (hey, it&#8217;s software!) and that&#8217;s the lack of RESTability.  I&#8217;m really keen on using <span class="caps">REST</span> interfaces where possible, as I&#8217;ve found them remarkably easy to reuse.  Ruby <em>appears</em> to go some way towards this, by focusing on a very nice clean <span class="caps">URL</span> structure.  But one key aspect is missing: dispatch on method names.  As Mark Nottingham <a href="http://www.mnot.net/blog/2003/12/08/http_api">pointed out</a>, to get a good RESTful interface, you need to dispatch on both <span class="caps">URI</span> and method name.</p>
<p>The good news is that Ruby is architected really well, so to get this kind of behaviour should simply be a case of subclass <a href="http://api.rubyonrails.com/classes/ActionController/Base.html">ActiveController::Base</a> or perhaps the Dispatcher itself.  I dunno.  But it looks eminently doable.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2005/04/28/ruby-on-rails-and-rest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

