<?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>Bizcoder &#187; REST</title>
	<atom:link href="http://www.bizcoder.com/index.php/tag/rest/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bizcoder.com</link>
	<description>Developing business applications for small businesses</description>
	<lastBuildDate>Sat, 28 Aug 2010 10:44:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Agent Fielding is on a mission</title>
		<link>http://www.bizcoder.com/index.php/2010/08/28/agent-fielding-is-on-a-mission/</link>
		<comments>http://www.bizcoder.com/index.php/2010/08/28/agent-fielding-is-on-a-mission/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 10:34:06 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HTTPClient]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.bizcoder.com/index.php/2010/08/28/agent-fielding-is-on-a-mission/</guid>
		<description><![CDATA[This is a continuation of a series on a Rest Agent library I am building for accessing REST apis.&#160; The first post is here and and the second is here. So far the only significant operation that we enabled our RestAgent to perform is NavigateTo().&#160; However, for a RestAgent on a mission, going places is [...]]]></description>
			<content:encoded><![CDATA[<p>This is a continuation of a series on a Rest Agent library I am building for accessing REST apis.&#160; The first post is <a href="http://www.bizcoder.com/index.php/2010/08/09/rest-agent-an-introduction/">here</a> and and the second is <a href="http://www.bizcoder.com/index.php/2010/08/12/rest-agent-uses-hypermedia/">here</a>. </p>
<p>So far the only significant operation that we enabled our RestAgent to perform is NavigateTo().&#160; However, for a RestAgent on a mission, going places is only half the story, the other major purpose of the agent is to gather content.</p>
<p>I was planning to show some real examples of missions using Stack Overflow’s API, but I ended up spending so much time explaining why it currently would not work, that my points were lost.&#160; So forgive me as I continue with a somewhat more hypothetical example.&#160; We are going to use an instance of our RestAgent to do a mashup of Twitter users and Stackoverflow users.</p>
<div>
<pre class="csharpcode">var agentFielding = <span class="kwrd">new</span> RestAgent(<span class="kwrd">new</span> HttpClient()); 

agentFielding.RegisterMediaType(“application/twitterdoc+xml”,
                                    <span class="kwrd">new</span> TwitterMediaHandler());
agentFielding.RegisterMediaType(“application/stackoverflowdoc+xml”,
                                    <span class="kwrd">new</span> StackOverflowMediaHandler());</pre>
</div>
<p>In the following code, Agent Fielding retrieves my Twitter followers and attempts to find matching accounts on Stack Overflow.&#160; In order to interpret the representations that will be retrieved from these two sites, we are going to pretend that these sites actually return non-generic media types and we register handlers for these media types that will transform the wire representation into strong types.</p>
<p>The first step is to navigate Twitter and retrieve the user profiles of my followers:</p>
<div>
<pre class="csharpcode">agentFielding.NavigateTo(<span class="kwrd">new</span> Uri(“http:<span class="rem">//api.twitter.com/”));</span>
var userSearch = agentFielding.CurrentLinks(“UserSearch”);
userSearch.SetParameter(&quot;darrel_miller”);
agentFielding.NavigateTo(userSearch);

var followersLink = agentFielding.CurrentLinks[“Followers”);
agentFielding.NavigateTo(followersLink);

var twitterUserProfiles = <span class="kwrd">new</span> List&lt;TwitterUserProfile&gt;();
var followerLinks = agentFielding.GetCurrentLinks(l=&gt; l.Relation.Name == ”Follower”];
<span class="kwrd">foreach</span>(Link followerLink <span class="kwrd">in</span> followerLinks) {

  var twitterProfile = agentFielding.GetContent(followerLink).ReadAsTwitterUserProfile();
  twitterUserProfiles.Add(twitterProfile);

}</pre>
</div>
<p>Now we have a list of TwitterUserProfile objects from which we can retrieve the name and search on Stack Overflow.</p>
<div>
<pre class="csharpcode">agentFielding.NavigateTo(<span class="kwrd">new</span> Uri(“http:<span class="rem">//api.stackoverflow.com/1.0/”));</span> 

agentFielding.NavigateTo(agent.CurrentLinks[“Users”]);
var searchLink = agent.CurrentLinks[“Search”];
var foundProfiles = <span class="kwrd">new</span> List&lt;StackOverflowUserProfile&gt;();
<span class="kwrd">foreach</span>(var profile <span class="kwrd">in</span> twitterUserProfiles) {   searchLink.SetParameter(profile.UserName);
  agentFielding.NavigateTo(searchLink); 

  var matchingUserLinks = agentFielding.GetCurrentLinks(l=&gt; l.Relation.Name == ”User”])
  <span class="kwrd">foreach</span>(Link userLink <span class="kwrd">in</span> matchingUserLinks) {
       var content = agentFielding.GetContent(userLink);
       foundProfiles.Add(content.ReadAsStackOverflowUserProfile();
  }
}</pre>
</div>
<p>Don’t get too hung up on the precise details of the above, there is a bit of smoke and mirrors going on.&#160; I’m really just trying to convey the concept that the same agent class can be used to navigate multiple different services.&#160; This brings the concept of the uniform interface a little further into the client code.&#160; </p>
<p>My hope is that in the future that REST api producers will supply media type handlers for their custom media types and we can use a standardized agent like interface for navigating any REST api.&#160; There will be no need the API producers to create complete client side facades.</p>
<p>There is still plenty of coupling in the above example, when it comes to handling specific representations and knowing about the existence of specific links, there is plenty of service specific code.&#160; This is especially true of these type of scripted or (machine to machine) interactions.&#160; Machines are really dumb, so they need to understand a lot of specifics of the services that they are interacting with.&#160; In the next article I’m going to start digging into how you can use an agent to react to a human driven application, and that will&#160; further reduce the coupling.&#160; </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizcoder.com/index.php/2010/08/28/agent-fielding-is-on-a-mission/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rest Agent uses hypermedia</title>
		<link>http://www.bizcoder.com/index.php/2010/08/12/rest-agent-uses-hypermedia/</link>
		<comments>http://www.bizcoder.com/index.php/2010/08/12/rest-agent-uses-hypermedia/#comments</comments>
		<pubDate>Thu, 12 Aug 2010 11:46:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HTTPClient]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.bizcoder.com/index.php/2010/08/12/rest-agent-uses-hypermedia/</guid>
		<description><![CDATA[As I alluded to in my first post, REST clients really should be driven by hypermedia.&#160; So how can our RestAgent class access this hypermedia and its links.&#160; Ideally, given a single root URI, I would like to be able to do: var agent = new RestAgent(new HttpClient()); agent.NavigateTo(new Uri(“http://api.stackoverflow.com/”)); var questionsLink = agent.CurrentLinks[“Questions”] agent.NavigateTo(questionsLink); [...]]]></description>
			<content:encoded><![CDATA[<p>As I alluded to in <a href="http://www.bizcoder.com/index.php/2010/08/09/rest-agent-an-introduction/">my first post</a>, REST clients really should be driven by hypermedia.&#160; So how can our RestAgent class access this hypermedia and its links.&#160; Ideally, given a single root URI, I would like to be able to do:</p>
<div>
<pre class="csharpcode">var agent = <span class="kwrd">new</span> RestAgent(<span class="kwrd">new</span> HttpClient());
agent.NavigateTo(<span class="kwrd">new</span> Uri(“http:<span class="rem">//api.stackoverflow.com/”)); </span>
var questionsLink = agent.CurrentLinks[“Questions”]
agent.NavigateTo(questionsLink);
var questions = agent.CurrentContent.ReadAsJson(); </pre>
</div>
<p>Before I talk about the magic that is going on under the covers here, let me take a little jab at my friend StackOverflow.&#160; The above code would not work, because when the team created the api, they chose not to put a root representation on the API. Making the request to the root of the api actually redirects to an html page with API documentation.&#160; I’ve tried scraping the urls out of that document, but it is proving to be painful.</p>
<h3>The Link Class</h3>
<p>The CurrentLinks property makes a dictionary of links available based on the links contained in the current content and potentially links that were included in the header.&#160; You will notice that the second call to NavigateTo passes a “Link”, not a URL.&#160; So what’s the difference?&#160; Here is a basic implementation of the Link class:</p>
<div>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> Link {

  <span class="kwrd">public</span> <span class="kwrd">string</span> Name{ get; set;}
  <span class="kwrd">public</span> LinkRelation Relation{ get; set;}
  <span class="kwrd">public</span> Uri Url { get; set;}
  <span class="kwrd">public</span> HttpMethod Method { get; set;}
  <span class="kwrd">public</span> HttpContent Content {get; set;}

  <span class="kwrd">public</span> Dictionary&lt;Parameter&gt; QueryParameters {get; set;}
  <span class="kwrd">public</span> Dictionary&lt;Parameter&gt; PathParameters {get; set;}

}</pre>
</div>
<p>The Link class holds plenty of additional information that is needed to allow the NavigateTo method to transfer to a new state.&#160; The Link objects are created from information contained in retrieved hypermedia content.&#160; If the HttpMethod is a PUT or a POST then the Content property can be used to hold the entity that will be sent to the origin server.&#160; </p>
<p>The LinkRelation property is critical concept.&#160; The Link Relation is one of the two points of coupling between the client and the server.&#160; The other being the media-type.&#160; From an architectural point of view the Link Relation describes the relationship between two resources.&#160; For example, if you have a representation A that contains a link to resource B with the relation “edit”, this can be interpreted as B allows you to “edit” A.&#160; IANA keeps a registry of well known link relations here <a href="http://www.iana.org/assignments/link-relations/link-relations.txt">http://www.iana.org/assignments/link-relations/link-relations.txt</a>.&#160; The WHATWG group are also maintaining a list here <a href="http://wiki.whatwg.org/wiki/RelExtensions">http://wiki.whatwg.org/wiki/RelExtensions</a>.</p>
<p>From an implementation perspective, the Link Relation can be used to tell the client mechanical information about how to perform the HTTP request.&#160; For example, what HTTP method to use, what content needs to be posted back to the server, if any. It also can be used to tell the client what query string parameters are valid.&#160; Arguably you can introduce any kind of arbitrary significance to a link relation as long as you are prepared to put up with the client/server coupling.</p>
<p>I have been experimenting with implementing LinkRelation as an actual class instead of just an identifer.&#160; Many different link relations have similar sets of behaviour and by creating a base class with some standard attributes it is possible to represent specific link relations as derived classes and still have plenty of generic mechanisms that process links without scattering the code base with fragile switch statements.&#160; Hopefully as we go into more detail I will show some examples that take advantage of this LinkRelation base class.</p>
<p>So far I have only used very simple URI templates and so my needs have been satisfied with just a collection of query parameter values and path parameter values.&#160; The current draft of the URI template specification introduces many more variants that I could be supported by the Link class.</p>
<p>The Name property is the black sheep of the Link class.&#160; I’m not convinced that we really need this property.&#160; However, I include it to support the scenario where there are multiple links within a hypermedia document that has the same LinkRelation.&#160; How a client is supposed to differentiate between those different links without introducing out of band coupling is not always clear to me.&#160; If the current representation is to be rendered to the user as a set of links then the user should be capable of deciding which they wish to follow.&#160; However, in a scripted (ie. machine 2 machine) scenario, it becomes highly suspect if the script starts referring to link names.&#160; Depending on how precise the media type, is, the link names could be pre-specified in the media-type.&#160; Or code-download could be used to activate links with particular names.&#160; The final solution that I have seen is to drop the name property completely and use very specific link relation values.&#160; I’m not a big fan of this approach because I think it leads to the same explosion problems as using extremely specific media-types.&#160; Highly specific media-types and link relations destroy the possibility of serendipitous reuse.</p>
<h3>Hypermedia Content</h3>
<p>So now, you have an idea of how I handle links, let’s look at how those links get created in the first place.&#160; As I mentioned before, the CurrentLinks dictionary is populated from the CurrentContent.&#160; The question of course is how can the generic RestAgent know how to pull links out of content that could be any media type.&#160; The solution is a plug in model that allows handlers to be registered in a media type handler registry.&#160; </p>
<p>Behind the scenes I use MEF to load up the media type handlers, but I stuck an interface in front, mainly because I’m not very experienced with MEF and I wasn’t exactly sure how to setup unit tests using MEF.&#160; With the interface I can easily create a fake registry.</p>
<div>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">interface</span> IHandlerRegistry {
        IMediaTypeHandler GetHandler(ContentType contentType);
    }</pre>
</div>
<p>Media type handlers I will cover in more detail at a later date.&#160; All we care about for this series of articles, is that they can be used to do two things:&#160; 1) they can convert the stream of bytes coming from the http response into a class that implements IHypermediaContent and 2) they can create and run a controller with RunController(HttpResponseMessage response) method that will “do” whatever that media type is supposed to do.&#160; I realize that sounds very vague, but vague is good when we don’t want to introduce coupling <img src='http://www.bizcoder.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
<div>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">interface</span> IMediaTypeHandler {
    IHypermediaContent GetContent(HttpContent content);
    IMediaTypeController RunController(HttpResponseMessage message);
}</pre>
</div>
<p>For this article I’m going to ignore RunController and we will get to human driven clients in an upcoming article.&#160; That leaves us with GetContent that returns an IHypermediaContent interface.&#160; That interface looks like this: </p>
<div>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">interface</span> IHypermediaContent {
       IDictionary&lt;<span class="kwrd">string</span>, Link&gt; Links { get; }
   } </pre>
</div>
<p>Not exactly complex to implement!&#160; Consider what it would take to write a handler that processes, HTML, XHTML, Atom Feeds, <a href="http://restafari.blogspot.com/2010/06/please-accept-applicationhalxml.html">HAL</a>, or even one that attempts to scrape links out of Json or generic XML based on some link convention.&#160; </p>
<h3>Magical Links</h3>
<p>Pulling this all back together, when you navigate the agent to a particular location on the web, the agent will identify the media type of the returned response, determine a handler for that media type, allow the handler to process the bytes and extra the links and store them in a dictionary available via the CurrentLinks property of the agent. </p>
<p>Here is a completely hypothetical use of the RestAgent to crawl safe links on a site: </p>
<div>
<pre class="csharpcode">var agent = <span class="kwrd">new</span> RestAgent(<span class="kwrd">new</span> HttpClient(), <span class="kwrd">new</span> Uri(“http:<span class="rem">//mythical.com/hypermediaService”));</span>
ExploreLinks(agent);

<span class="kwrd">public</span> <span class="kwrd">void</span> ExploreLinks(RestAgent agent) {
var links = CopyLinks(agent.CurrentLinks);
<span class="kwrd">foreach</span>(Link link <span class="kwrd">in</span> links) {
    <span class="kwrd">if</span> (Link.Method == HttpMethod.GET &amp;&amp; Link.LinkRelation.RequiresParameters == <span class="kwrd">false</span>) {
        agent.NavigateTo(link);
        Explore(agent);
    }
}
}</pre>
</div>
<p>To keep things simple, I only traverse links whose LinkRelation specifies a GET is the appropriate verb and only links that do not require parameters.&#160; </p>
<p>I realize that this is still not a very useful example, but enough of the pieces are in place so that in the next article I will talk more about how to get the agent to actually do something useful. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizcoder.com/index.php/2010/08/12/rest-agent-uses-hypermedia/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Rest Agent &#8211; An introduction</title>
		<link>http://www.bizcoder.com/index.php/2010/08/09/rest-agent-an-introduction/</link>
		<comments>http://www.bizcoder.com/index.php/2010/08/09/rest-agent-an-introduction/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 11:14:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HTTPClient]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.bizcoder.com/index.php/2010/08/09/rest-agent-an-introduction/</guid>
		<description><![CDATA[You might say I’m a bit of a fan of the REST architectural style. Let me provide a little background to clarify why REST is important to me, so you can better understand my underlying objectives.&#160; If we have similar objective then maybe this series of posts will be of interest to you. I write [...]]]></description>
			<content:encoded><![CDATA[<p>You might say I’m a bit of a fan of the REST architectural style. Let me provide a little background to clarify why REST is important to me, so you can better understand my underlying objectives.&#160; If we have similar objective then maybe this series of posts will be of interest to you.</p>
<p>I write distributed business applications for a living and to date, it appears that I end up supporting the code I write for at least 10 to 15 years.&#160; When ever you deploy and update distributed systems there is a nasty side effect of having different components to update and trying to deploy them simultaneously is rife with pitfalls.&#160; Deploying an update to a server compared with updating software on 50 client machines is just a completely different set of problems and keeping them synchronized can be challenging.&#160; </p>
<p>I realize that many people would argue that using a web browser as a client platform would solve my distribution problems.&#160; It would solve the distribution problem, but it would also introduce a whole host of other problems for the types of applications I write.&#160; Browser based apps are awesome for many things, some things they are not so awesome for.</p>
<p>The REST constraints allow you to manage the coupling between the distributed components and allow them to evolve more independently. This allows the system as a whole to evolve incrementally over long periods of time.&#160; I need this kind of robustness in my line of work. </p>
<p>In the three years that I have been building RESTful systems I have seen lots written about how to design and implement RESTful APIs but very little has been written about how REST client applications need to be written.&#160; The few people I have seen talk about it are <a href="http://www.stucharlton.com/blog/archives/2010/03/building-a-restful-hypermedia.html">Stu Charlton</a> and <a href="http://restfulie.caelumobjects.com/">Guilherme Silveira</a>.</p>
<p>This is hopefully the first in a series of blog posts where I cover what I am learning about writing client applications that are part of a RESTful distributed system.</p>
<h4>REST clients are a different breed</h4>
<p>One of the core concepts when designing a REST client is the notion of Hypermedia as the Engine of Application State.&#160; I’m not going to try and explain what I think it means, as many people far more eloquent than I, have tried and yet its meaning is still much debated.&#160; Instead, I would prefer to show some code that I believe embodies the concept.</p>
<p>My REST client applications are built around a class called RestAgent.&#160; I like to imagine my instance of the RestAgent class as little guy travelling across the web making requests and fetching data on my behalf [1].&#160; This agent is responsible for holding all of my application state and for transferring state to and from origin servers. </p>
<p>In its most simple incarnation the class looks something like:</p>
<pre class="csharpcode"><span class="kwrd">public</span> <span class="kwrd">class</span> RestAgent(HttpClient client) {

<span class="kwrd">  private</span> Uri _CurrentLocation;
<span class="kwrd">  private</span> HttpContent_CurrentContent;

<span class="kwrd">  public</span> <span class="kwrd">void</span> NavigateTo(Uri url) {

    _CurrentContent = client.Get(url).Content;
    _CurrentLocation = url;
  }

}</pre>
<p>The RestAgent itself does not know any of the nitty gritty details of how to do HTTP interactions, so I need to provide it with some kind of Http client library.&#160; Obviously, I’ve chosen to use the Microsoft Http client, but in theory any library could work.&#160; </p>
<p>At this point the only thing that the RestAgent is really capable of doing is navigating to the provided url and retreiving the returned content.&#160; The important concept here is that at any one point in time, the RESTAgent can only be in one place.&#160; As we expand on the capabilities of the agent we will allow it to accumulate content during its travels and the aggregate of all of that content will be the “application state”, but if our client application really needs to be in multiple places at once, then we will create multiple agent instances.</p>
<p>For just a small taste of how you might use this RestAgent, </p>
<p>&#160;</p>
<div>
<pre class="csharpcode">var agent = <span class="kwrd">new</span> RestAgent(<span class="kwrd">new</span> HttpClient());

agent.NavigateTo(<span class="kwrd">new</span> Uri(“http:<span class="rem">//api.stackoverflow.com/1.0/questions”)); </span>
var questions = agent.CurrentContent.ReadAsJson();

agent.NavigateTo(“http:<span class="rem">//search.twitter.com/search.atom?q=@darrel_miller”) </span>
var mentions = agent.CurrentContent.ReadAsSyndicationFeed();</pre>
</div>
<p>&#160;</p>
<p>In the next post, I’ll talk more about hypermedia and how the agent can use links from hypermedia content to travel further and gather more content.</p>
<p>&#160;</p>
<p>&#160;</p>
<p>[1]&#160; I originally wanted to call this class AgentFielding to anthropomorphize the class even more, but it seemed a touch presumptuous <img src='http://www.bizcoder.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizcoder.com/index.php/2010/08/09/rest-agent-an-introduction/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The StackOverflow question that couldn’t stay open</title>
		<link>http://www.bizcoder.com/index.php/2010/07/21/the-stackoverflow-question-that-couldnt-stay-open/</link>
		<comments>http://www.bizcoder.com/index.php/2010/07/21/the-stackoverflow-question-that-couldnt-stay-open/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 16:08:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.bizcoder.com/index.php/2010/07/21/the-stackoverflow-question-that-couldnt-stay-open/</guid>
		<description><![CDATA[This http://stackoverflow.com/questions/3285704/why-does-rest-exist is the question that I want to give an answer to.&#160; I am answering here because people keep closing it.&#160; Sorry, the post refers directly to issues raised in the question and so won’t make much sense without reading the question first.&#160; I would even recommend reading version of the question prior to [...]]]></description>
			<content:encoded><![CDATA[<p>This <a href="http://stackoverflow.com/questions/3285704/why-does-rest-exist">http://stackoverflow.com/questions/3285704/why-does-rest-exist</a> is the question that I want to give an answer to.&#160; I am answering here because people keep closing it.&#160; Sorry, the post refers directly to issues raised in the question and so won’t make much sense without reading the question first.&#160; I would even recommend reading version of the question prior to editing as it shows more clearly the frustration of the poster.</p>
<h3>A canary in a coal mine.</h3>
<p> I have been waiting for a question like this for close to a year now. It was inevitable that this day would come and I am sure we are going to see many more questions like this in the coming months.<br />
<h3>The warning signs</h3>
<p>You are absolutely correct, it does take longer to build RESTful clients than SOAP clients. The SOAP toolkits take away lots of boilerplate code and make client proxy objects available with almost no effort. With a tool like Visual Studio and a server URL I can be accessing remote objects of arbitrary complexity, locally in under five minutes. </p>
<p>Services that return application/xml and application/json are so annoying for client developers. What are we supposed to do with that blob of data? </p>
<p>Fortunately, lots of sites that provide REST services also provide a bunch of client libraries so that we can use those libraries to get access to a bunch of strongly typed objects. Seems kind of dumb though. If they had used SOAP we could have code-gen&#8217;d those proxy classes ourselves. </p>
<p>SOAP overhead, ha. It&#8217;s latency that kills. If people are really concerned about the number of excess bytes going across the wire then maybe HTTP is not the right choice. Have you seen how many bytes are used by the user-agent header?</p>
<p>Yeah, have you ever tried using a web browser as debugging tool for anything other than HTML and javascript. Trust me it sucks. You can only use two of the verbs, the caching is constantly getting in the way, the error handling swallows so much information, it&#8217;s constantly looking for a goddamn favicon.ico. Just shoot me. </p>
<p>Readable URL. Only nouns, no verbs. Yeah, that&#8217;s easy as long as we are only doing CRUD operations and we only need to access a hierarchy of objects in one way. Unfortunately most applications need a wee bit more functionality than that. </p>
<h3>The impending disaster</h3>
<p>There are a metric boatload of developers currently developing applications that integrate with REST services who are in the process of coming to the same set of conclusions that you have. They were promised simplicity, flexibility, scalability, evolvabilty and the holy grail of serendipitous reuse. The characteristics of the web itself, how can things go wrong.</p>
<p>However, they are finding that versioning is just as much of a problem, but the compiler doesn&#8217;t help detect issues. The hand written client code is a pain to maintain as the data structures evolve and URLs get refactored. Designing APIs around just nouns and four verbs can be really hard, especially with RESTful Url zealots telling you when you can and cannot use query strings. </p>
<p>Developers are going to start asking why are we wasting our effort on support both Json formats and Xml formats, why not just focus our efforts on one and do it well? </p>
<h3>How did things go so wrong</h3>
<p>I&#8217;ll tell you what went wrong. We as developers let the marketing departments take advantage of our primary weakness. Our eternal search for the silver bullet blinded us to the reality of what REST really is. On the surface REST seems so easy and simple. Name your resources with Urls and use GET, PUT, POST and DELETE. Hell, us devs already know how to do that, we have been dealing with databases for years that have tables and columns and SQL statements that have SELECT, INSERT, UPDATE and DELETE. It should have been a piece of cake. </p>
<p>There are other parts of REST that some people discuss, such as self-descriptiveness, and the hypermedia constraint, but these constraints are not so simple as resource identification and the uniform interface. The seem to add complexity where the desired goal is simplicity. </p>
<p>This watered down version of REST became validated in developer culture in many ways. Server frameworks were created that encouraged Resource Identification and the uniform interface, but did nothing to support the other constraints. Terms started to float around differentiating the approaches, (HI-REST vs LO-REST, Corporate REST vs Academic REST, REST vs RESTful). </p>
<p>A few people scream out that if you don&#8217;t apply all of the constraints it&#8217;s not REST. You will not get the benefits. There is no half REST. But those voices were labelled as religious zealots who were upset that their precious term had been stolen from obscurity and made mainstream. Jealous people who try to make REST sound more difficult than it is. </p>
<p>REST, the term, has definitely become mainstream. Almost every major web property that has an API supports &quot;REST&quot;. Twitter and Netflix are two very high profile ones. The scary thing is that I can only think of one public API that is self-descriptive and there are a handful that truly implement the hypermedia constraint. Sure some sites like StackOverflow and Gowalla support links in their responses, but there are huge gaping holes in their links. The StackOverflow API has no root page. Imagine how successful the web site would have been if there was no home page for the web site! </p>
<h3>You were misled I&#8217;m afraid</h3>
<p>If you have made it this far, the short answer to your question is those APIs (Netflix and Twitter) do not conform to all of the constraints and therefore you will not get the benefits that REST apis are supposed to bring. </p>
<p>REST clients do take longer to build than SOAP clients but they are not tied to one specific service, so you should be able to re-use them across services. Take the classic example, of a web browser. How many services can a web browser access? What about a Feed Reader? Now how many different services can the average Twitter client access? Yes, just one. </p>
<p>REST clients are not supposed to be built to interface with a single service, they are supposed to be built to handle specific media types that could be served by any service. The obvious question to that is, how can you build a REST client for a service that delivers application/json or application/xml. Well you can&#8217;t. That&#8217;s because those formats are completely useless to a REST client. You said it yourself, </p>
<blockquote><p>you have to make &quot;guesses&quot; as to what will come back across the pipe as there is no real schema or reference document </p>
</blockquote>
<p>You are absolutely correct for services like Twitter. However, the self-descriptive constraint in REST says that the HTTP content type header should describe exactly the content that is being transmitted across the wire. Delivering application/json and application/xml tells you nothing about the content. </p>
<p>When it comes to considering the performance of REST based systems it is necessary look at the bigger picture. Talking about envelope bytes is like talking about loop unwinding when comparing a quick-sort to a shell-sort. There are scenarios where SOAP can perform better, and there are scenarios where REST can perform better. Context is everything. </p>
<p>REST gains much of its performance advantage by being very flexible about what media types it supports and by having sophisticated support for caching. For caching to work well though nearly all of the constraints must be adhered to. </p>
<p>Your last point about readable urls is by far the most ironic. If you truly commit to the hypermedia constraint, then every URL could be a GUID and the client developer would lose nothing in readability. </p>
<p>The fact that URIs should be opaque to the client is one of the most key things when developing REST systems. Readable URLs are convenient for the server developer and well structured URLs make it easier for the server framework to dispatch requests, but those are implementation details that should have no impact on the developers consuming the API. </p>
<p>The Twitter API is not even close to being RESTful and that is why you are unable to see any benefit to using it over SOAP. The Netflix API is much closer but it&#8217;s use of generic media types demonstrates that failing to adhere to even a single constraint can have a profound impact on the benefits derived from the service. </p>
<h3>It may not be all their fault</h3>
<p>I&#8217;ve done a whole lot of dumping on the service providers, but it takes two to dance RESTfully. A service may follow all of the constraints religiously and a client can still easily undo all of the benefits. </p>
<p>If a client hard codes urls to access certain types of resources then it is preventing the server from changing those urls. Any kind URL construction based on implicit knowledge of how the service structures its urls is a violation. </p>
<p>Making assumptions about what type of representation will be returned from a link can lead to problems. Making assumptions about the content of the representation based on knowledge that is not explicitly stated in the HTTP headers is definitely going to create coupling that will cause pain in the future. </p>
<h3>Should they have used SOAP?</h3>
<p> Personally, I don&#8217;t think so. REST done right allows a distributed system to evolve over the long term. If you are building distributed systems that have components that are developed by different people and need to last for many years, then REST is a pretty good option.   </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizcoder.com/index.php/2010/07/21/the-stackoverflow-question-that-couldnt-stay-open/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Woe is me, the WOA unmanifesto</title>
		<link>http://www.bizcoder.com/index.php/2009/12/14/woe-is-me-the-woa-unmanifesto/</link>
		<comments>http://www.bizcoder.com/index.php/2009/12/14/woe-is-me-the-woa-unmanifesto/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 21:53:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.bizcoder.com/index.php/2009/12/14/woe-is-me-the-woa-unmanifesto/</guid>
		<description><![CDATA[This started as a comment on the blog post here, but it got too long. I have two questions for Dion and a few comments. 1) Have you read (not just skimmed a few times) Roy&#8217;s dissertation on REST? 2) Have you written both a REST service and a REST client that is in production [...]]]></description>
			<content:encoded><![CDATA[<p>This started as a comment on the blog post <a href="http://hinchcliffe.org/archive/2009/12/14/18179.aspx">here</a>, but it got too long.</p>
<p>I have two questions for Dion and a few comments.   <br />1) Have you read (not just skimmed a few times) Roy&#8217;s dissertation on REST?    <br />2) Have you written both a REST service and a REST client that is in production today? </p>
<p>With all due respect, without actually creating REST applications, I don&#8217;t think anyone is qualified to attempt to define principles relating to REST and based on your Twitter bio: </p>
<blockquote><p>Internationally recognized business strategist, enterprise architect, keynote speaker, author, blogger, and consultant on Web 2.0, SOA, and next-gen business</p>
</blockquote>
<p>you sound like a talker, not a walker.&#160; Forgive me if I am wrong.</p>
<p>Here are my comments on the suggested principles, I’ve tried to be as constructive as I can muster:</p>
<p>Principle #1: I think it is a significant oversimplification to refer to a resource&#160; as data.&#160; </p>
<p>Principle #2: Can you clarify what you mean by &quot;favor granularity and depth in linkage&quot;? </p>
<p>Principle #3: I am pretty sure no-one has ever said that URIs should be self descriptive.&#160; In REST the request message should be self-descriptive, the URI being just one part of the message.&#160;&#160; The statement “URI should indicate what data format is being used and indicate nested elements with URL segmentation” is way too strong, maybe if you replace “should” with “can”.</p>
<p>Principle #4:&#160; This idea that all legacy databases should be exposed as data-oriented REST apis is crazy-talk.&#160; REST is an architectural style for building distributed APPLICATIONS.&#160; I.e. Exposing functionality over the web, not just data. Your example of cloud computing API’s is a perfect example.&#160; The Sun Cloud API is one of the best REST examples out there at the moment, but it exposes functionality for manipulating those cloud applications.&#160; Functions like turning the instances on and off.&#160; It’s far more than just exposing data.</p>
<p>Principle #5:&#160; You seem to be describing benefits rather than a principle.</p>
<p>#6:&#160; Ok</p>
<p>#7: I don’t get this concept at all.&#160; Does this mean we should all be using text/plain if we want the widest audience?</p>
<p>#8: Maybe I don’t want my resources to crawled by an SEO.&#160; Even if I do, conforming to the uniform interface and delivering standard format representations should be sufficient to meet any search engine requirements.</p>
<p>#9:&#160; “higher realized value”?&#160; Are you sure this isn’t another one of those spoof manifestos?</p>
<p>#10: I think you are referring to the idea that a resource should only have one canonical URI.&#160; I see this topic debated regularly and I do not yet see any consensus.</p>
<p>Ok, I give up for the moment, I’m a bit too depressed to continue.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizcoder.com/index.php/2009/12/14/woe-is-me-the-woa-unmanifesto/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Oh Data</title>
		<link>http://www.bizcoder.com/index.php/2009/11/30/oh-data/</link>
		<comments>http://www.bizcoder.com/index.php/2009/11/30/oh-data/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 14:44:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[OData]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.bizcoder.com/index.php/2009/11/30/oh-data/</guid>
		<description><![CDATA[Since the recent PDC09 I have been obsessing over OData and I need to write this post just to get it out of my head.&#160; Microsoft has made it obvious that they are taking this protocol very seriously by integrating it into Sharepoint, Visual Studio, RIA Services, PowerPivot, and I expect to see it in [...]]]></description>
			<content:encoded><![CDATA[<p>Since the recent PDC09 I have been obsessing over OData and I need to write this post just to get it out of my head.&#160; Microsoft has made it obvious that they are taking this protocol very seriously by integrating it into Sharepoint, Visual Studio, RIA Services, PowerPivot, and I expect to see it in the next version of Office and in the Dynamics products.&#160; I think it is a great direction to be headed but I also have concerns.</p>
<p>Let me start by quoting the most important paragraph from the <a href="http://download.microsoft.com/download/B/0/B/B0B199DB-41E6-400F-90CD-C350D0C14A53/[MC-APDSU].pdf">document</a> that explains how OData extends AtomPub.</p>
<blockquote><p>AtomPub, as specified in [RFC5023], in combination with the extensions defined in this document, is appropriate for use in Web services which need a uniform, flexible, general purpose interface for exposing create retrieve update delete (CRUD) operations on a data model to clients. It is less suited to Web services that are primarily method-oriented or in which data operations are constrained to certain prescribed patterns.</p>
</blockquote>
<p>Let me paraphrase that.&#160; If all your service is going to do for your client is <strong>“CRUD” on generic data then OData is appropriate</strong>.&#160; As long as everyone keeps this in mind going forward we should not run into too much trouble.&#160; However, there is a problem with this statement.&#160; <strong>REST is not really appropriate for doing CRUD</strong>.&#160; Harry Pierson sums it up best <a href="http://devhawk.net/2007/05/24/REST+Is+Neither+CRUD+Nor+CRAP.aspx">here</a>.&#160; What is worse, is that I am seeing some of the people behind the OData spec equating OData with <a href="http://blogs.msdn.com/aconrad/archive/2009/11/18/odbc-for-the-web.aspx">ODBC</a>.&#160; </p>
<p>The problem is that <strong>ODBC allows clients to initiate transactions</strong> across multiple requests. REST does not allow this as it would violate the stateless constraint.&#160; <strong>REST does not need this</strong> because it is intended to address a completely different layer of the application architecture than ODBC.&#160; REST provides a way to deliver Domain services.&#160; I.e.&#160; If you maintain weather data, REST provides you a easy way to expose “Today’s Weather”, “Last Week’s weather for Detroit”, “Average Rainfall in Orlando for the month of June”.&#160; ODBC is aimed at the layer that exposes the data points for a specific place at a specific date and time.&#160; </p>
<p>ODBC exposes dumb data, REST exposes intelligently presented information.</p>
<p>In an ODBC application it is the client that does something intelligent with the data before presenting it to the user.&#160; In a REST application, usually the client simply makes the “intelligent information” pretty.&#160; REST and ODBC are not comparable.</p>
<p>So is OData useful?&#160; Absolutely it is useful to people who want to manipulate generic information, like for example Sharepoint lists, or data to feed into PowerPivot or Excel.&#160; If you have a need to expose a generic data store to a client that will do graphing, statistical analysis, or some kind of visualization like rendering Mars Rover data then it could be very useful.&#160; </p>
<p>However, if you want to provide a <strong>service that delivers intelligent information</strong> that is specific to a particular domain then I believe and apparently the authors of the spec believe that <strong>OData is not appropriate</strong>.</p>
<p>Beyond my fear of developers attempting to use OData for unintended purposes there are few other things that I think should be fixed in the OData spec.&#160; </p>
<p>The Atom Entry content element should <strong>not use application/xml as the media type</strong>.&#160; The content contains XML that is specifically related to the Entity Data Model and should be identified as such.&#160; A media type such as application/EDM-Instance+xml may be sufficient.&#160; What would be even better is if that content element contained a <strong>link to the CSDL file that defines the EntityType</strong> and that is currently accessed by constructing an URI with [Service]/$metadata.&#160; Oh yeah, and maybe a precise media type on the metadata would be good too!</p>
<p>Client side URI construction is really nasty habit to get into.&#160; I think for the most part, MS can get away with the construction of query parameters like $skip, $top, and $orderby, but to actually construct the path segments of a URI is just going lead to client-server coupling that will hurt in the future.</p>
<p>I haven’t read the entire OData spec in detail but it is interesting to see the <strong>complications that are introduced because they have not strictly followed the hypermedia constraint</strong>.&#160; For example, it has become necessary to create custom HTTP headers to manage versioning of the “protocol” due to the use of client constructed URIs.&#160; If those URIs were delivered as Links with rel attributes then the <strong>versioning would be limited to the media type of the content</strong>.&#160; Yeah, I realize that you can’t create links for every combination of query parameter/ sub resource, but hey, I’m not the one saying that creating a REST interface for generic data was a good idea in the first place <img src='http://www.bizcoder.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .</p>
<p>It is fascinating how difficult it is to beat the RPC mentality out of people.&#160; Even though the OData spec is built on top of AtomPub, the authors have gone to <strong>great lengths to document the OData protocol in RPC terms</strong> and then map the RPC call to an HTTP request.&#160; When you find yourself creating documentation titles like “RetreiveEntitySet Request”, “RetreiveEntity Request”, “RetreiveComplexType Request”, “RetreivePrimitiveProperty Request” and there is actually some valuable information that distinguishes one of those requests from the other then you are violating the uniform interface.&#160; The idea is that the documentation can read “Use HTTP GET to retrieve representation of the resource from the URI”. Look at how simple the AtomPub <a href="http://tools.ietf.org/html/rfc5023#section-5.1">spec</a> is in comparison.</p>
<p>I think it is <strong>great that Microsoft have recognized the value of a RESTful protocol like AtomPub</strong> and they have taken the steps to incorporate this type of interface into many of their products.&#160; I understand what they are trying to do with their URL construction techniques, I know exactly why they have introduced a MERGE verb and have created a batch request mechanism, because I too have been down this path before.&#160; However, while there some areas they are justified in straying from the REST constraints, there are others that are definitely not and the protocol is suffering from it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizcoder.com/index.php/2009/11/30/oh-data/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WCF REST Starter Kit Preview 2</title>
		<link>http://www.bizcoder.com/index.php/2009/03/14/wcf-rest-starter-kit-preview-2/</link>
		<comments>http://www.bizcoder.com/index.php/2009/03/14/wcf-rest-starter-kit-preview-2/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 00:30:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HTTPClient]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.bizcoder.com/index.php/2009/03/14/wcf-rest-starter-kit-preview-2/</guid>
		<description><![CDATA[I have been looking thought the latest release of the WCF REST Starter Kit and there are some interesting things there.&#160; Especially the new HttpClient class in the Microsoft.Http namespace.&#160; I will not talk about the server side of things because I really don&#8217;t have anything nice to say and until I have some constructive [...]]]></description>
			<content:encoded><![CDATA[<p>I have been looking thought the latest release of the WCF REST Starter Kit and there are some interesting things there.&nbsp; Especially the new HttpClient class in the Microsoft.Http namespace.&nbsp; I will not talk about the server side of things because I really don&#8217;t have anything nice to say and until I have some constructive criticism to give I&#8217;m going to keep my mouth shut.</p>
<p>However, the new client side library is designed to make it easier to talk to HTTP endpoints and it seems to be quite nice.&nbsp; It is 3500 lines of code, so there is a fair bit of stuff in there, layered on top of HttpWebRequest and I was curious to see what it could do.</p>
<p>I started by looking at the enclosed sample, unhelpfully named &#8220;WpfSample&#8221; and I got a little sidetracked from my exploration.&nbsp; This sample is actually a very neat little http request builder tool.&nbsp; I know this is a cool tool to have, because I have an almost identical one that we built to help us test REST services.&nbsp; Testing with real web browsers is really annoying because they do all sorts of magic stuff behind the scenes, they are very picky about what content-types they will render and they keep trying to find a favicon!&nbsp; </p>
<p>Anyway, I was curious to see how this tool made use of the HttpClient class but I was rather dismayed to see <strong>all</strong> of the code in the &#8220;code behind&#8221; of the Window1.xaml file.&nbsp; This makes it really difficult to distinguish between what code is relevant to the web request and what is just UI gunk.&nbsp; To add salt to the wound, it is a WPF app that uses no data binding and no Commands, just events manipulating the contents of UI elements.&nbsp; It was a nice looking, handy WPF app that demonstrated this new spiffy HttpClient library with the architecture of a college student&#8217;s VB4 project.</p>
<p>Ok, I know it is just a sample.&nbsp; However, everything that Microsoft puts out is viewed by people who are learning.&nbsp; If Microsoft create samples with crappy architecture, why are we surprised when developers create applications with crappy architectures.</p>
<p>So despite the ton of work that I was supposed to be doing today, I refactored it.&nbsp; I created an MVC type of structure with databinding and routed commands.&nbsp; If you get the <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24644">WCF REST Starter Kit</a> and extract the zip file that gets put in the &#8220;C:\Program Files (x86)\Microsoft WCF REST&#8221; folder you will find a solution named Product.sln.&nbsp; Just add my project which is in the zip file below and you will have, what I hope is a much easier to read version of the HttpClient sample.</p>
<p><a href="http://www.tavis.ca/files/httpClientGui.zip">http://www.tavis.ca/files/httpClientGui.zip</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizcoder.com/index.php/2009/03/14/wcf-rest-starter-kit-preview-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The mystery of the trailing slash and the relative url</title>
		<link>http://www.bizcoder.com/index.php/2009/02/24/the-mystery-of-the-trailing-slash-and-the-relative-url/</link>
		<comments>http://www.bizcoder.com/index.php/2009/02/24/the-mystery-of-the-trailing-slash-and-the-relative-url/#comments</comments>
		<pubDate>Wed, 25 Feb 2009 02:47:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.bizcoder.com/index.php/2009/02/24/the-mystery-of-the-trailing-slash-and-the-relative-url/</guid>
		<description><![CDATA[I had heard conflicting rumours about the significance of the trailing slash, so I decided to go googling.&#160; If you explore the first few hits you will find all sorts of discussions about cool urls, the impact on SEO, the performance benefits of avoiding server redirects, amongst other stuff.&#160; However, I found nothing that seemed [...]]]></description>
			<content:encoded><![CDATA[<p>I had heard conflicting rumours about the significance of the trailing slash, so I decided to go googling.&#160; If you explore the first few hits you will find all sorts of discussions about cool urls, the impact on SEO, the performance benefits of avoiding server redirects, amongst other stuff.&#160; However, I found nothing that seemed to have a critical impact on the functionality of a web application.</p>
<p>My interest in the trailing slash had been provoked by my attempts to use relative urls in some documents that I was returning from a REST server.&#160; Sometimes the relative urls would work sometimes they wouldn&#8217;t.</p>
<p>The performance benefit discussion that I had found related to the fact that web servers will automatically redirect to an url with the trailing slash if the last segment points to a folder instead of file.&#160; </p>
<p>e.g. A request to <a href="http://example.org/folder">http://example.org/folder</a> would actually be redirected to <a href="http://example.org/folder/default.htm">http://example.org/folder/default.htm</a> (or whatever file is set as the default file)</p>
<p>As is probably obvious to anyone who has done any amount of web development, all relative urls processed by a web server are relative to the folder in which the containing file is located.&#160; Mechanically, this means the last segment is of the url is stripped of and the relative url is added.&#160; A detailed explanation of how a relative url is resolved can be found <a href="http://www.faqs.org/rfcs/rfc2396.html">here</a>.</p>
<p>The key point that I want to draw attention to is that the behaviour is pretty natural when you are pulling static files from folders on a web server.&#160; It gets less obvious when you start using dynamically generated resources with the style of urls that are common in the REST world.</p>
<p>E.g.&#160; Say you retrieve a resource such as <a href="http://example.org/customer/101">http://example.org/customer/101</a> and it contains an element &lt;link href=&quot;address&quot;/&gt;.&#160; Common sense dictates that you are trying to get to <a href="http://example.org/customer/101/address">http://example.org/customer/101/address</a>, but that is not how it would be resolved.&#160; The url would actually be resolved as <a href="http://example.org/customer/address">http://example.org/customer/address</a></p>
<p>The problem is that the server no longer has a file/folder distinction, so the routing infrastructure doesn&#8217;t know whether it should append a slash to your url or not.</p>
<p>From what I&#8217;ve seen of Microsoft&#8217;s new URL routing infrastructure that is used by ASP.NET MVC and the WCF Rest toolkits, the url gets passed through with or without the slash depending on what the user typed.&#160; This is a problem if you want to use relative urls in your representations.</p>
<p>I decided that I would include xml:base in documents so that at least I could be explicit about where my relative urls were relative to.&#160; This way I don&#8217;t care if the source url ends with a slash or not.&#160; I make sure that all my xml:base urls end in a slash and so far this strategy is working for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizcoder.com/index.php/2009/02/24/the-mystery-of-the-trailing-slash-and-the-relative-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gems from rest-discuss</title>
		<link>http://www.bizcoder.com/index.php/2009/02/05/gems-from-rest-discuss/</link>
		<comments>http://www.bizcoder.com/index.php/2009/02/05/gems-from-rest-discuss/#comments</comments>
		<pubDate>Fri, 06 Feb 2009 01:18:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.bizcoder.com/index.php/2009/02/05/gems-from-rest-discuss/</guid>
		<description><![CDATA[Just catching up on some posts in the Yahoo group rest-discuss and there is some great wisdom in there. &#160; It is the hypermedia constraint that makes REST as a stylegreater than the sum of its constraints. It is the focal pointand amplifier of all the constraints.&#160; &#8211; Aristotle Pagaltzis &#160; Well-designed URIs are great, [...]]]></description>
			<content:encoded><![CDATA[<p>Just catching up on some posts in the Yahoo group rest-discuss and there is some great wisdom in there.</p>
<p>&nbsp;</p>
<blockquote><p>It is the hypermedia constraint that makes REST as a style<br />greater than the sum of its constraints. It is the focal point<br />and amplifier of all the constraints.&nbsp; &#8211; Aristotle Pagaltzis</p>
</blockquote>
<p>&nbsp;<br />
<blockquote>
<p>Well-designed URIs are great, but they don&#8217;t influence whether something is RESTful or not.
<p>- Stefan Tilkov</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.bizcoder.com/index.php/2009/02/05/gems-from-rest-discuss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to write a document describing a REST Api</title>
		<link>http://www.bizcoder.com/index.php/2008/10/22/how-to-write-a-document-describing-a-rest-api/</link>
		<comments>http://www.bizcoder.com/index.php/2008/10/22/how-to-write-a-document-describing-a-rest-api/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 13:15:29 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[REST]]></category>

		<guid isPermaLink="false">http://www.bizcoder.com/index.php/2008/10/22/how-to-write-a-document-describing-a-rest-api/</guid>
		<description><![CDATA[Roy Fielding wrote this post recently on the proliferation of APIs that claim to be REST but are breaking some of the fundamental constraints of a REST style architecture. I was most struck by what Roy seems to be saying is required to document a REST Api. A description of the media types that are [...]]]></description>
			<content:encoded><![CDATA[<p>Roy Fielding wrote <a href="http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven">this</a> post recently on the proliferation of APIs that claim to be REST but are breaking some of the fundamental constraints of a REST style architecture.</p>
<p>I was most struck by what Roy seems to be saying is required to document a REST Api.</p>
<ol>
<li>A description of the media types that are used throughout the API.
<li>A root Url.</li>
</ol>
<p>That is it.&nbsp; If you look at most API specs you will see a long laundry list of the endpoints that can be used to access various pieces of functionality.&nbsp; In REST, you don&#8217;t want to provide a list of endpoints because then you are allowing the client to bake that knowledge into its implementation.&nbsp; That&#8217;s coupling.</p>
<p>I&#8217;m going to reach a little here and add some of my own conclusions.&nbsp; You can couple on the media types.&nbsp; If you need to create your own media type to allow the client to process the data on the server, then so be it.&nbsp; At some point the client has to understand what to do with the data it is being sent.&nbsp; </p>
<p>However, don&#8217;t couple on endpoints, there is really no need.&nbsp; Use the root url to deliver some kind of discovery document that allows the client to find the other available resources.</p>
<p>It&#8217;s kind of like how a web site works&#8230; <img src='http://www.bizcoder.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bizcoder.com/index.php/2008/10/22/how-to-write-a-document-describing-a-rest-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
