<?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/"
		xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>Frank Carver&#039;s Punch Barrel &#187; REST</title>
	<atom:link href="http://blog.punchbarrel.com/tag/rest/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.punchbarrel.com</link>
	<description>Frank Carver&#039;s musings about software and life</description>
	<lastBuildDate>Thu, 08 Dec 2011 22:58:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<copyright>Copyright &#xA9; Frank Carver&#039;s Punch Barrel 2010 </copyright>
	<managingEditor>frank.carver@googlemail.com (Frank Carver&#039;s Punch Barrel)</managingEditor>
	<webMaster>frank.carver@googlemail.com (Frank Carver&#039;s Punch Barrel)</webMaster>
	<ttl>1440</ttl>
	<image>
		<url>http://punchbarrel.com/images/punchbarrel-144.jpg</url>
		<title>Frank Carver&#039;s Punch Barrel</title>
		<link>http://blog.punchbarrel.com</link>
		<width>144</width>
		<height>144</height>
	</image>
	<itunes:subtitle></itunes:subtitle>
	<itunes:summary>Frank Carver&#039;s musings about software and life</itunes:summary>
	<itunes:keywords></itunes:keywords>
	<itunes:category text="Society &#38; Culture" />
	<itunes:author>Frank Carver&#039;s Punch Barrel</itunes:author>
	<itunes:owner>
		<itunes:name>Frank Carver&#039;s Punch Barrel</itunes:name>
		<itunes:email>frank.carver@googlemail.com</itunes:email>
	</itunes:owner>
	<itunes:block>no</itunes:block>
	<itunes:explicit>no</itunes:explicit>
	<itunes:image href="http://punchbarrel.com/images/punchbarrel-144.jpg" />
		<item>
		<title>REST and versioning, a more concrete example.</title>
		<link>http://blog.punchbarrel.com/2010/06/15/rest-and-versioning-a-more-concrete-example/</link>
		<comments>http://blog.punchbarrel.com/2010/06/15/rest-and-versioning-a-more-concrete-example/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 23:11:39 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[version]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=1541</guid>
		<description><![CDATA[There&#8217;s an interesting discussion going on at The Wisdom of Ganesh in which Ganesh Prasad and &#8220;Integral ):( Reporting&#8221; (presumably the &#8220;JJ Dubray&#8221; mentioned in the article) are trying to work out some issues around versioning, REST and SOAP. This post is also referenced and commented on at infoQ. In the 14th comment to the [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s an interesting discussion going on at <a href="http://wisdomofganesh.blogspot.com/2010/06/does-rest-need-versioning.html">The Wisdom of Ganesh</a> in which Ganesh Prasad and &#8220;<em>Integral ):( Reporting</em>&#8221; (presumably the &#8220;JJ Dubray&#8221; mentioned in the article) are trying to work out some issues around versioning, REST and SOAP. This post is also referenced and commented on at <a href="http://www.infoq.com/news/2010/06/rest-versioning">infoQ</a>.</p>
<p>In the 14th comment to the original article, JJ calls for a real-world example &#8211; this is a good idea which should help ground the discussion and diffuse the temptation to communicate in abstract principles.  In the spirit of this request, I will describe an example based on problems I faced in a previous job.</p>
<p>The first version of the system we were working on consisted of a server component, coded in Java, which provided remote services to several client systems. Each of the client systems was a Java web application, responsible for providing customer-specific web pages and navigation using the services and content provided by the central server. For some customers there would be just one instance of the web client, for others with greater load there would be several.</p>
<p>The server system was responsible for managing products for sale, including descriptions in multiple languages, format and compatibility meta-data, thumbnail images in several sizes, prices in multiple currencies. As well as access to individual items and collections, a search facility provided a way to discover or look up products. The server also managed customer details and purchase histories, and handled both delivery of content and general messaging (by email and SMS) during the purchase process. The client systems were responsible for display and navigation of a product catalogue, customer branding, &#8220;shopping cart&#8221;, login/logout, and everything else a user experiences.</p>
<p>The API between client and server included ways to list products by category, fetch details of specific products, search using a variety of criteria, make and cancel purchases, fetch and update user data and so on.</p>
<p>I suggest this should be a reasonable system on which to base a discussion &#8211; it embodies similar concepts to many other systems, and is neither trivial nor impossible to build. Interestingly, both SOAP and REST versions of the interface between the clients and the server were implemented at different points in the life of the product.</p>
<p>So, on to versioning. It seems to me that there are several kinds of changes which might require versioning. I will list a few here, but I welcome suggestions for others I might have missed.</p>
<ul>
<li>The first deployment of the system worked with only a single currency. The move to multiple currencies was a potentially major change in the interaction between client and server, even though each client works only in a single currency.</li>
<li>The customer for one client implementation required the provision of extra services, specific to their market, which were not required by (and should not be available to) other clients.</li>
<li>The initial version of the search facility returned data for all matches, with paging through the results implemented entirely on the client. When there was a lot of data in the catalogue this became an unacceptable performance bottleneck, especially as results beyond the first few pages were hardly ever viewed. An alternative approach was suggested where a client would request a specified page (of a specified page size) from the search results. This required changes in both the search request and search results.</li>
<li>A new source of products introduced the idea of collections. Items in a collection could be purchased individually or as a bundle. Viewing a collection while browsing, searching, or in a user&#8217;s purchase history, should allow a user to &#8220;drill in&#8221; to the collection to view the items within it. Items located while searching should indicate how to purchase the collection, as well as how to purchase the individual item.</li>
</ul>
<p>Is this a useful amount of detail for a scenario? I have my own experiences of working with this system and the choices we made, but I&#8217;d love to read any suggestions for how you might handle any of the transitions above in a live system with multiple client systems deployed, many of which can not be changed easily or often, and a server full of historical purchase data. Procedural remoting approaches (SOAP, XML-RPC and Java RMI etc.) and resource-based approaches (REST) are all welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2010/06/15/rest-and-versioning-a-more-concrete-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Test-Driven Development of HTTP and REST interfaces with Mojasef</title>
		<link>http://blog.punchbarrel.com/2009/01/07/test-driven-development-of-http-and-rest-interfaces-with-mojasef/</link>
		<comments>http://blog.punchbarrel.com/2009/01/07/test-driven-development-of-http-and-rest-interfaces-with-mojasef/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 09:15:42 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[mojasef]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[stringtree]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[tests]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=691</guid>
		<description><![CDATA[Test-Driven Development (TDD) of HTTP and REST interfaces can be tricky. This post contains some examples of how to do it using the open source Mojasef toolkit. I was prompted to write this post after recently finding and fixing an irritating bug using just this technique. First, let&#8217;s set the scene. In TDD the rules [...]]]></description>
			<content:encoded><![CDATA[<p>Test-Driven Development (TDD) of HTTP and REST interfaces can be tricky. This post contains some examples of how to do it using the open source <a href="http://mojasef.stringtree.org/">Mojasef</a> toolkit. I was prompted to write this post after recently finding and fixing an irritating bug using just this technique.</p>
<p>First, let&#8217;s set the scene. In TDD the rules are very simple: No production code is written without a failing test; just enough code is written to satisfy the current set of tests; duplication is mercilessly refactored. TDD is a very powerful and effective technique which can improve both the quality and delivery time of software. HTTP and REST interfaces provide access to a system or component using the HTTP protocol. This access may be by fetching HTML or WML pages, for example, or it may be by sending,  receiving and updating resources in some other format such as XML or JSON.</p>
<p>For a first scenario imagine we have an existing HTTP interface for which we want to write a client using TDD. This service is relatively simple to start with. To send a message requires a POST request to a particular URL with two parameters &#8220;destination&#8221; and &#8220;text&#8221;. If the destination is valid, the text message is sent to the destination and a &#8220;200&#8243; status code is returned. If the destination is not recognized, a &#8220;404&#8243; status code is returned. This interface is <em>so</em> simple that it is tempting to just write the client, test it manually and move on. But if we were to do that, then we might not think of all the test case possibilities, and there would be no regression tests to help protect the software from unexpected side-effects later. So we opt to do the right thing, and use TDD.</p>
<p>For the sake of simplicity, I will assume we are using the Stringtree HTTPClient as <a href="http://blog.punchbarrel.com/2008/01/07/a-simple-http-client-part-1-overview/">described in an earlier post</a>. So let&#8217;s start with a simple test to make sure the code compiles and the test libraries and stuff are in place:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.stringtree.http.*</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MessageSendingTest <span style="color: #000000; font-weight: bold;">extends</span> junit.<span style="color: #006633;">framework</span>.<span style="color: #006633;">TestCase</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testExceptionFromUnknownURL<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    Form form <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    form.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;destination&quot;</span>, <span style="color: #0000ff;">&quot;name@example.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    form.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span>, <span style="color: #0000ff;">&quot;hello from HTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    HTTPClient client <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HTTPClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      client.<span style="color: #006633;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://localhost:9999/send&quot;</span>, form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;should throw an exception&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This test serves two purposes. First, compiling it helps drive the structure of the test case, what classes need to be imported and so on. Second it documents the expected behaviour of our client if the server is not running or not where it is expected to be.  I always like to start with this sort of &#8220;null&#8221; test case wherever possible. Once we get this test working we are ready to move on to the next step, testing against an actual server.</p>
<p>It might be possible to test against a real server, perhaps by manually examining log files, or checking the actual receipt of a message. Feel free to do that, but understand that that is really integration testing rather than unit testing, and neither helps us design and debug the client, nor document and enforce the proper behaviour of our code once we move on to other work. To gain these benefits we need a server which may be started, examined and stopped quickly and under the control of a simple unit test. This is where <a href="http://mojasef.stringtree.org/">Mojasef</a> comes in.</p>
<p>Mojasef is a server and web application framework designed for efficient test-driven development of web applications. Although usually used for building applications, it is just as suitable for building test harnesses. In this case we will build a simple application which implements the HTTP interface described above. And yes, we will do it using TDD, so we leave the MessageSendingTest for the moment and start a new one to drive our test harness without requiring HTTP. As usual, I start with a &#8220;null&#8221; test to get started:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MessageHarnessTest <span style="color: #000000; font-weight: bold;">extends</span> junit.<span style="color: #006633;">framework</span>.<span style="color: #006633;">TestCase</span> <span style="color: #009900;">&#123;</span>
  MessageHarness harness<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    harness <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MessageHarness<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testNoAction<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    assertFalse<span style="color: #009900;">&#40;</span>harness.<span style="color: #006633;">wasCalled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This won&#8217;t compile without a MessageHarness class, so let&#8217;s make the minimum necessary.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MessageHarness <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> wasCalled<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: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Good, our test now runs, so let&#8217;s add some behaviour. First another test:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testCalledWithoutArguments<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    harness.<span style="color: #006633;">send</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    assertTrue<span style="color: #009900;">&#40;</span>harness.<span style="color: #006633;">wasCalled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>To make this compile we need to add another method to MessageHarness</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> send<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Our new test fails, so we need to make it work.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MessageHarness <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> called <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> wasCalled<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> called<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> send<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    called <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>That seems enough to start with. Now back to the main test case. Add a new test to call the application we have just built over HTTP and check that all the communication stuff works. With a bit of refactoring to keep the tests clean and duplication low.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.stringtree.http.*</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.stringtree.mojasef.standalone.InlineServer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MessageSendingTest <span style="color: #000000; font-weight: bold;">extends</span> junit.<span style="color: #006633;">framework</span>.<span style="color: #006633;">TestCase</span> <span style="color: #009900;">&#123;</span>
  HTTPClient client<span style="color: #339933;">;</span>
  Form form<span style="color: #339933;">;</span>
  InlineServer server<span style="color: #339933;">;</span>
  MessageHarness app<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    client <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HTTPClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    form <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Form<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    app <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MessageHarness<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    server <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> InlineServer<span style="color: #009900;">&#40;</span>app, <span style="color: #0000ff;">&quot;9998&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    server.<span style="color: #006633;">start</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> tearDown<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	server.<span style="color: #006633;">halt</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testExceptionFromUnknownURL<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    form.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;destination&quot;</span>, <span style="color: #0000ff;">&quot;name@example.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    form.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span>, <span style="color: #0000ff;">&quot;hello from HTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
      client.<span style="color: #006633;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://localhost:9999/send&quot;</span>, form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      fail<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;should throw an exception&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">Exception</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> testHarnessWiring<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    form.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;destination&quot;</span>, <span style="color: #0000ff;">&quot;unknown@example.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    form.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span>, <span style="color: #0000ff;">&quot;hello from HTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    assertFalse<span style="color: #009900;">&#40;</span>app.<span style="color: #006633;">wasCalled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    client.<span style="color: #006633;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://localhost:9998/send&quot;</span>, form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    assertTrue<span style="color: #009900;">&#40;</span>app.<span style="color: #006633;">wasCalled</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This probably needs a bit of explanation. The MessageHarness class we produced above is a Mojasef web application. Really, without any other configuration, base classes or nonsense. It&#8217;s just a &#8220;plain old Java object&#8221; (POJO). The job of the Mojasef code is to take an object of that class and make its methods available as HTTP URLs.</p>
<p>To serve it over HTTP we <em>could</em> use a MojasefServlet and run it in any Servlet Container, but for this test we want an ultra-light server which can be started and stopped in a test. So we use the InlineServer provided in the Mojasef jar. It&#8217;s a real HTTP server which you can use from a regular web browser, but it&#8217;s mainly designed for streamlined use in tests.</p>
<p>This server is configured to serve the MessageHarness application on port 9998. Having configured the server we start it in startUp and stop it in tearDown to ensure that nothing is left behind between tests.</p>
<p>The new test makes a HTTP request to the freshly started server, then checks (by calling the MessageHarness method we created earlier) that the test harness application was successfully called. This verifies that the server has been correctly started and called.</p>
<p>It&#8217;s still not really testing the message API. To do that we need more tests.</p>
<p>Now, we know from the introduction above that our resource should return a HTTP 404 (&#8220;not found&#8221;) error if we try to send to an unrecognised address.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> test404FromUnknownDestination<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    form.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;destination&quot;</span>, <span style="color: #0000ff;">&quot;unknown@example.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    form.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span>, <span style="color: #0000ff;">&quot;hello from HTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Document</span> result <span style="color: #339933;">=</span> client.<span style="color: #006633;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://localhost:9998/send&quot;</span>, form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;404&quot;</span>, result.<span style="color: #006633;">getHeader</span><span style="color: #009900;">&#40;</span>HTTPClient.<span style="color: #006633;">HTTP_RESPONSE_CODE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Making this test work is pretty simple, especially as we have no other tests which say anything about the HTTP Response code. The only &#8220;cleverness&#8221; is that we now need to use some slightly smarter features of the Mojasef code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.stringtree.finder.StringKeeper</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.stringtree.mojasef.HTTPConstants</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MessageHarness <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> called <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> wasCalled<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> called<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> send<span style="color: #009900;">&#40;</span>StringKeeper context<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    called <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    context.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>HTTPConstants.<span style="color: #006633;">RESPONSE_CODE</span>, <span style="color: #0000ff;">&quot;404&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Mojasef will try a variety of ways to call a public method. We have seen the basic one &#8211; a method with no parameters mapped directly to a URL. This is another one &#8211; a  method taking a &#8220;context&#8221; as an argument. This context will be pre-loaded with any POST or URL parameters, as well as any request headers and plenty of other stuff which is not of interest right now. This context also provides a way of setting information to be sent back to the client.</p>
<p>Now, our application code is passing all its tests, but it does so by returning a &#8220;404&#8243; error code for all requests. This is not really desirable behaviour, so we need another test:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> test200FromKnownDestination<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    form.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;destination&quot;</span>, <span style="color: #0000ff;">&quot;known@example.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    form.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span>, <span style="color: #0000ff;">&quot;hello from HTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Document</span> result <span style="color: #339933;">=</span> client.<span style="color: #006633;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://localhost:9998/send&quot;</span>, form<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;200&quot;</span>, result.<span style="color: #006633;">getHeader</span><span style="color: #009900;">&#40;</span>HTTPClient.<span style="color: #006633;">HTTP_RESPONSE_CODE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>This test fails, so we need to modify the application to add some understanding of the supplied form data.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.stringtree.finder.StringKeeper</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.stringtree.mojasef.HTTPConstants</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MessageHarness <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000066; font-weight: bold;">boolean</span> called <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> wasCalled<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> called<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> send<span style="color: #009900;">&#40;</span>StringKeeper context<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    called <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">String</span> destination <span style="color: #339933;">=</span> context.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;destination&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;known@example.com&quot;</span>.<span style="color: #006633;">equals</span><span style="color: #009900;">&#40;</span>destination<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        context.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>HTTPConstants.<span style="color: #006633;">RESPONSE_CODE</span>, <span style="color: #0000ff;">&quot;200&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
        context.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>HTTPConstants.<span style="color: #006633;">RESPONSE_CODE</span>, <span style="color: #0000ff;">&quot;404&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Now we reach an interesting point in the development process. It is perfectly feasible to continue in this vein, step-by-step bringing the application into existence. However, even the streamlined InlineServer still needs to set itself up, bind and unbind ports, deal with network traffic and so on. This is considerably slower than a regular method call, and as more tests are added the test case will continue to slow down.</p>
<p>The advantages of the Mojasef approach to web applications really begin to pay off at this point. The tests we already have prove the basics of HTTP Communication are working, so further tests do not really need to bother with HTTP, <em>provided the tests are testing exactly the same code</em>. Luckily (as pointed out earlier) a Mojasef application is just a regular Java class, which needs no modification to be tested using regular JUnit tests. Here are the same tests as above, but implemented as simple method calls:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.stringtree.finder.StringKeeper</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.stringtree.mojasef.HTTPConstants</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.stringtree.mojasef.HTTPConstants</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MessageProcessingTest <span style="color: #000000; font-weight: bold;">extends</span> junit.<span style="color: #006633;">framework</span>.<span style="color: #006633;">TestCase</span> <span style="color: #009900;">&#123;</span>
  StringKeeper context<span style="color: #339933;">;</span>
  MessageHarness app<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> setUp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    context <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MapStringKeeper<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    app <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> MessageHarness<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> test404FromUnknownDestination<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    context.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;destination&quot;</span>, <span style="color: #0000ff;">&quot;unknown@example.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    context.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span>, <span style="color: #0000ff;">&quot;hello from HTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    app.<span style="color: #006633;">send</span><span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;404&quot;</span>, context.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>HTTPConstants.<span style="color: #006633;">RESPONSE_CODE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> test200FromKnownDestination<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span> <span style="color: #009900;">&#123;</span>
    context.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;destination&quot;</span>, <span style="color: #0000ff;">&quot;known@example.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    context.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text&quot;</span>, <span style="color: #0000ff;">&quot;hello from HTTP&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    app.<span style="color: #006633;">send</span><span style="color: #009900;">&#40;</span>context<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    assertEquals<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;200&quot;</span>, context.<span style="color: #006633;">get</span><span style="color: #009900;">&#40;</span>HTTPConstants.<span style="color: #006633;">RESPONSE_CODE</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>I shall stop there, leaving the development of the rest of the application to interested readers.</p>
<p>From the above steps, I hope you can see that the normal process of Test-Driven Development is quite possible for both web applications, and web-application clients. When using a framework which gets all the fiddly stuff out of the way it can even be as simple, quick and productive as in-process development.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2009/01/07/test-driven-development-of-http-and-rest-interfaces-with-mojasef/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>IBM&#8217;s BPM Zero Project: RESTful Worflow Management</title>
		<link>http://blog.punchbarrel.com/2008/12/30/ibms-bpm-zero-project-restful-worflow-management/</link>
		<comments>http://blog.punchbarrel.com/2008/12/30/ibms-bpm-zero-project-restful-worflow-management/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 12:41:42 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[BPEL]]></category>
		<category><![CDATA[BPM]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RPC]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=944</guid>
		<description><![CDATA[From an SOA architectural view, Business Process Management and workflow orchestration seems an obvious component of a large system. However, when I see this idea moved wholesale into the world of REST, I worry that a significant point has been missed. InfoQ: IBM&#8217;s BPM Zero Project: RESTful Worflow Management The part of BPEL workflow orchestration [...]]]></description>
			<content:encoded><![CDATA[<p>From an SOA architectural view, Business Process Management and workflow orchestration seems an obvious component of a large system. However, when I see this idea moved wholesale into the world of REST, I worry that a significant point has been missed.</p>
<p><a href="http://www.infoq.com/news/2008/12/bpm-zero">InfoQ: IBM&#8217;s BPM Zero Project: RESTful Worflow Management</a></p>
<p>The part of BPEL workflow orchestration which makes sense when used with traditional services (presented via SOAP or other RPC mechanisms) is the connecting together of displarate executable chunks into a larger executable chunk. In effect, BPEL used as an over-arching programming language.</p>
<p>The point that is missed when this approach is applied to REST is that REST is not about executable services, but about resources. A REST-style of over-arching connection would somehow represent disparate resources as a larger resource. This is not at all what BPEL orchestration does.</p>
<p>The practical upshot of this is that SOA workflow management can only work with REST resources which may also be considered as executable services. While such things do exist, they are an unusual and very rare subset of REST. Attempting to integrate REST resources using BPEL typically leads to one of three outcomes: (1) the integration is limited to those resources which are also services, and thus is so limited as to be hardly useful. (2) useful resources are converted or wrapped to appear as executable services, defeating the point of REST. (3) The project is abandoned as impossible, or simply fails.</p>
<p>As a simple &#8220;litmus test&#8221; for whether you are making effective and proper use of REST: Will your application still work if all the collaborating &#8220;services&#8221; are replaced by simple files or static web pages? If not, then you need to work harder at understanding REST.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2008/12/30/ibms-bpm-zero-project-restful-worflow-management/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Describing RESTful Applications</title>
		<link>http://blog.punchbarrel.com/2008/12/22/describing-restful-applications/</link>
		<comments>http://blog.punchbarrel.com/2008/12/22/describing-restful-applications/#comments</comments>
		<pubDate>Mon, 22 Dec 2008 11:04:01 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[content]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[ontology]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[rfc]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[tree]]></category>
		<category><![CDATA[URI]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=925</guid>
		<description><![CDATA[I have read a lot of faux-REST APIs recently, which are essentially just HTTP/XML or HTTP/JSON remote services, and still need a client to be pre-built with specialist knowledge of URI structure. &#8220;Proper&#8221; REST allows a server to change its URIs however and whenever it likes, with client applications seamlessly adapting to the change. InfoQ [...]]]></description>
			<content:encoded><![CDATA[<p>I have read a lot of faux-REST APIs recently, which are essentially just HTTP/XML or HTTP/JSON remote services, and still need a client to be pre-built with specialist knowledge of URI structure. &#8220;Proper&#8221; REST allows a server to change its URIs however and whenever it likes, with client applications seamlessly adapting to the change.</p>
<p>InfoQ has published an excellent article describing an approach to building fully self-describing REST interfaces.</p>
<p><a href="http://www.infoq.com/articles/subbu-allamaraju-rest">InfoQ: Describing RESTful Applications</a></p>
<p>I still think more work is needed, though, particularly in the area of content types. The suggestion of <em>application/blah.whatever+xml</em> as per <a href="http://www.ietf.org/rfc/rfc3023.txt">RFC 3023</a> is certainly better than an unadorned <em>text/xml</em>, but still does not provide the flexibility for client applications to sensibly handle new, yet similar, content types. In particular that proposal is limited to XML, with no equivalent for JSON or other data description formats.</p>
<p>Alternative approaches such as <em>text/xml/blah/whatever</em> might allow a more general support. In this example, transport and storage responsibilities might only care that it is essentially a textual format (something which is worryingly implicit in <em>application/blah.whatever+xml</em>), while parsing components might only care that it is <em>text/xml</em>, and so on. There is then the possibility for further information to be encoded in the content type. Consider a type such <em>text/xml/link@href/whatever</em>, which might indicate a textual format, parsable as XML, in which relationship URIs are indicated as a link element with an href attribute, and so on.</p>
<p>While compelling, such an approach could easily lead to fragility, though. Such a representation implies that the range of available content types is a strict single-inheritance tree ontology, with all the familiar problems<br />
that entails.</p>
<p>Definitely an area for further research.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2008/12/22/describing-restful-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The REST Dialogues</title>
		<link>http://blog.punchbarrel.com/2008/12/18/the-rest-dialogues/</link>
		<comments>http://blog.punchbarrel.com/2008/12/18/the-rest-dialogues/#comments</comments>
		<pubDate>Thu, 18 Dec 2008 09:46:29 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[dialogue]]></category>
		<category><![CDATA[ebay]]></category>
		<category><![CDATA[integration]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[socratic]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=896</guid>
		<description><![CDATA[When I first encountered Duncan Cragg&#8217;s &#8220;REST dialogues&#8221; I was not sure how they would develop. As I have read more, I have become progressively more impressed. Cragg uses the style of a Socratic dialogue with an imaginary &#8220;eBay architect&#8221; to teach about the nature and use of REST techniques as an alternative to more [...]]]></description>
			<content:encoded><![CDATA[<p>When I first encountered Duncan Cragg&#8217;s &#8220;REST dialogues&#8221; I was not sure how they would develop. As I have read more, I have become progressively more impressed. Cragg uses the style of a Socratic dialogue with an imaginary &#8220;eBay architect&#8221; to teach about the nature and use of REST techniques as an alternative to more traditional approaches such as SOAP and SOA.</p>
<p>Recent dialogues on <a href="http://duncan-cragg.org/blog/post/business-conversations-rest-dialogues/">Business Conversations</a> and <a href="http://duncan-cragg.org/blog/post/distributed-observer-pattern-rest-dialogues/">The Distributed Observer Pattern</a> are particularly thought-provoking, but the whole growing series is definitely worth a read.</p>
<p><a href="http://duncan-cragg.org/blog/tag/dialogue/">The REST Dialogues</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2008/12/18/the-rest-dialogues/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>REST is not CRUD, and here&#8217;s why.</title>
		<link>http://blog.punchbarrel.com/2008/10/31/rest-is-not-crud-and-heres-why/</link>
		<comments>http://blog.punchbarrel.com/2008/10/31/rest-is-not-crud-and-heres-why/#comments</comments>
		<pubDate>Fri, 31 Oct 2008 17:22:26 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[CRUD]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=747</guid>
		<description><![CDATA[I have encountered several web articles recently which attempt to describe REST verbs (&#8220;get&#8221;, &#8220;put&#8221;, &#8220;post&#8221;, &#8220;delete&#8221;) in terms of traditional database CRUD (&#8220;create&#8221;, &#8220;read&#8221;, &#8220;update&#8221;, &#8220;delete&#8221;) operations, and then get stuck trying to map one set to the other. On the one hand, it&#8217;s easy to see why the confusion happens. Both sets have [...]]]></description>
			<content:encoded><![CDATA[<p>I have encountered several web articles recently which attempt to describe REST verbs (&#8220;get&#8221;, &#8220;put&#8221;, &#8220;post&#8221;, &#8220;delete&#8221;) in terms of traditional database CRUD (&#8220;create&#8221;, &#8220;read&#8221;, &#8220;update&#8221;, &#8220;delete&#8221;) operations, and then get stuck trying to map one set to the other.</p>
<p>On the one hand, it&#8217;s easy to see why the confusion happens. Both sets have four basic operations, and both sets are concerned with manipulation of stored resources, both have an operation called &#8220;delete&#8221;, and &#8220;read&#8221; sounds pretty much like &#8220;get&#8221;. However, that&#8217;s where the similarity stops.</p>
<p>For some recent examples of confusing REST and CRUD, see:</p>
<p><a href="http://blog.sidu.in/2008/03/rest-and-usablity-shouldnt-be-mixed.html">REST and usablity shouldn&#8217;t be mixed</a></p>
<p><a href="http://blog.sidu.in/2008/10/two-stage-resource-oriented-web.html">Two stage resource oriented web application architectures</a></p>
<p><a href="http://www.jroller.com/HazemBlog/entry/the_rules_behind_designing_a">Hazem Ahmed Saleh: The rules behind designing a good RESTful service</a>  </p>
<p>Even the, otherwise very good, <a href="http://duncan-cragg.org/blog/post/getting-data-rest-dialogues/">REST Dialogues</a> sometimes fall into this trap.</p>
<p>So, what is the difference?</p>
<p>&#8220;Get&#8221; and &#8220;read&#8221; are essentially the same, at least when it comes to fetching raw resource data. </p>
<p>There is a difference in usage, though. In REST a &#8220;get&#8221; fetches a single resource. CRUD, on the other hand, is often associated with relational databases, which excel in returning sets of results. The common REST approach to multiple results is to return a resource which includes URIs for each resource in the collection (perhaps also with some summary information); the REST client is then free to individually &#8220;get&#8221; any or all referenced resources which it requires, or if necessary to instead fetch them from a local cache. As an example, consider the loading of images in a web page.</p>
<p>&#8220;Delete&#8221;, although similar on the surface has some important differences underneath. </p>
<p>In CRUD, the relational heritage often implies the ability to do complex deletes, such as deleting all resources which meet some criteria. In REST the &#8220;delete&#8221; operation is a simple delete of the resource at a single URI. To delete multiple items using REST typically requires multiple, separate, &#8220;delete&#8221; requests.</p>
<p>&#8220;Put&#8221; and &#8220;update&#8221; can be similar or different depending on interpretation. </p>
<p>The REST &#8220;put&#8221; operation has strict and well-defined semantics. It ensures that the specified URI has the supplied resource. If the URI is invalid it fails; if the URI contains no resource the supplied resource is placed there; if the URI contains a different resource it is replaced with the supplied resource; if the URI contains the same resource there is no apparent change to the resource at the URI. The CRUD &#8220;update&#8221; operation, on the other hand is less well-defined. SQL standards do not include a &#8220;replace&#8221;, &#8220;put&#8221;, or &#8220;insert or update if exists&#8221; operation (although many vendor implementations implement such features in a non-standard way). With this in mind, some people interpret the CRUD &#8220;update&#8221; operation as equivalent to an SQL &#8220;update&#8221; statement (which only applies if the resource already exists), while others treat it more generally as any form of change which is not a &#8220;delete&#8221;.</p>
<p>This only leaves &#8220;post&#8221; and &#8220;create&#8221;. These are the most different of all. </p>
<p>In REST, &#8220;post&#8221; is used for any action which results in a resource change or side-effect, and cannot be repeated without the change or side-effect happening again. An SQL &#8220;insert&#8221; operation would be implemented as a REST &#8220;post&#8221;, for example, but so would an SQL &#8220;update&#8221; which increments a value, or the sending of an email. A practical rule of thumb is that a &#8220;post&#8221; should be simple and quick, leaving the way for future changes using &#8220;put&#8221; as soon as possible. A CRUD &#8220;create&#8221; is a quite different thing. &#8220;Create&#8221; explicitly creates a new resource, and is undefined if that resource already exists.</p>
<p>REST has no direct analogue of &#8220;create&#8221;. If it is needed (for example) to create and populate a new resource, it is typical to call &#8220;post&#8221; on some parent resource which results in the return of, or redirect to, a new (empty) URI, and then populate the URI with one or more &#8220;put&#8221; operations. This approach has the big advantage that the impact of an accidental re-&#8221;post&#8221; is minimised. In a well designed system, the creating of a new URI could be as low-impact as incrementing an integer, only requiring storage of resource data if/when it is later populated using &#8220;put&#8221;.</p>
<p>CRUD, on the other hand, has no direct analogue of &#8220;post&#8221;. A CRUD &#8220;create&#8221; will probably have side effects, as will some CRUD &#8220;update&#8221; operations. CRUD is also limited in that it does not include the concept of side-effects outside the resources being managed. There is no way to describe sending an email in terms of CRUD, for example.</p>
<p>In summary, the REST and CRUD are different in many ways, some subtle and some less so.</p>
<p>REST is an approach designed to enable scalable distributed applications to clearly distinguish actions which make no change and thus may be cached or repeated (&#8220;get&#8221;) from those which make a change but may be casually repeated without problems (&#8220;put&#8221;, &#8220;delete&#8221;) from those which should neither be repeated nor cached (&#8220;post&#8221;). This in turn enables intermediate software (be it in the form of libraries, reusable components, or entirely separate systems) to implement sensible optimisation and error-handling strategies without needing knowledge of the content or relationships of the resources.</p>
<p>CRUD is a description of some generic operations on stored data, with no particular intention of serving as a distribution protocol, and thus little or no planning for the mitigation of problems such as accidental duplicates, time-outs or lost requests.</p>
<p>Attempts, however well-intentioned, to explain one by analogy with the other run a great risk of increasing confusion rather than clearing it. If you are considering using such an analogy, please think twice.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2008/10/31/rest-is-not-crud-and-heres-why/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>What Makes Good REST?</title>
		<link>http://blog.punchbarrel.com/2008/10/24/what-makes-good-rest/</link>
		<comments>http://blog.punchbarrel.com/2008/10/24/what-makes-good-rest/#comments</comments>
		<pubDate>Fri, 24 Oct 2008 19:31:43 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[Fielding]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=725</guid>
		<description><![CDATA[REST is a very powerful way of thinking about application design, but it can be very hard to really understand. Several people including the originator of REST, Roy Fielding, have written on the subject, and InfoQ has attempted to summarise some of these articles. InfoQ: What Makes Good REST?]]></description>
			<content:encoded><![CDATA[<p>REST is a very powerful way of thinking about application design, but it can be very hard to really understand. Several people including the originator of REST, Roy Fielding, have written on the subject, and InfoQ has attempted to summarise some of these articles.</p>
<p><a href="http://www.infoq.com/news/2008/10/rest-api">InfoQ: What Makes Good REST?</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2008/10/24/what-makes-good-rest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>London Java Web User Group: Web apps and REST</title>
		<link>http://blog.punchbarrel.com/2008/10/13/london-java-web-user-group-web-apps-and-rest/</link>
		<comments>http://blog.punchbarrel.com/2008/10/13/london-java-web-user-group-web-apps-and-rest/#comments</comments>
		<pubDate>Mon, 13 Oct 2008 15:46:08 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[BOF]]></category>
		<category><![CDATA[london]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[usergroup]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=667</guid>
		<description><![CDATA[This looks interesting. Next Monday (20th October 2008) the London JAVAWUG will be holding a &#8220;Birds-of-a-Feather&#8221; session on the topic of Web applications and REST web services. Both are subjects near to my heart, so I might try and arrange a trip to &#8220;the smoke&#8221; that evening. Anyone else likely to be attending? JAVAWUG :: [...]]]></description>
			<content:encoded><![CDATA[<p>This looks interesting. Next Monday (20th October 2008) the London JAVAWUG will be holding a &#8220;Birds-of-a-Feather&#8221; session on the topic of Web applications and REST web services. Both are subjects near to my heart, so I might try and arrange a trip to &#8220;the smoke&#8221; that evening.</p>
<p>Anyone else likely to be attending?</p>
<p><a href="http://www.jroller.com/javawug/entry/javawug_bof_41_web_applications">JAVAWUG :: Java Web User Group :: London, UK :: Peter Pilgrim, Java Champion : Weblog</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2008/10/13/london-java-web-user-group-web-apps-and-rest/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to GET a Cup of Coffee</title>
		<link>http://blog.punchbarrel.com/2008/10/02/how-to-get-a-cup-of-coffee/</link>
		<comments>http://blog.punchbarrel.com/2008/10/02/how-to-get-a-cup-of-coffee/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 20:54:33 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[coffee]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=603</guid>
		<description><![CDATA[An intriguing and detailled example of implementing a real-world asynchronous workflow using REST. I&#8217;m not sure that I entirely agree with all the choices, but it&#8217;s well worth studying to see how capable REST can be. InfoQ: How to GET a Cup of Coffee]]></description>
			<content:encoded><![CDATA[<p>An intriguing and detailled example of implementing a real-world asynchronous workflow using REST. I&#8217;m not sure that I entirely agree with all the choices, but it&#8217;s well worth studying to see how capable REST can be.</p>
<p><a href="http://www.infoq.com/articles/webber-rest-workflow">InfoQ: How to GET a Cup of Coffee</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2008/10/02/how-to-get-a-cup-of-coffee/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>REST Eye for the SOA Guy</title>
		<link>http://blog.punchbarrel.com/2008/08/02/rest-eye-for-the-soa-guy/</link>
		<comments>http://blog.punchbarrel.com/2008/08/02/rest-eye-for-the-soa-guy/#comments</comments>
		<pubDate>Sat, 02 Aug 2008 21:20:45 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[Information]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://blog.punchbarrel.com/?p=250</guid>
		<description><![CDATA[Another interesting-looking Qcon presentation for the &#8220;to watch&#8221; queue. I&#8217;m getting a bit bored with the X eye for the Y guy title meme, though. InfoQ: REST Eye for the SOA Guy]]></description>
			<content:encoded><![CDATA[<p>Another interesting-looking Qcon presentation for the &#8220;to watch&#8221; queue. I&#8217;m getting a bit bored with the <em>X eye for the Y guy</em> title meme, though.</p>
<p><a href="http://www.infoq.com/presentations/rest-vinoski">InfoQ: REST Eye for the SOA Guy</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.punchbarrel.com/2008/08/02/rest-eye-for-the-soa-guy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.589 seconds -->

