<?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>Peter Williams &#187; web services</title>
	<atom:link href="http://barelyenough.org/blog/tag/web-services/feed/" rel="self" type="application/rss+xml" />
	<link>http://barelyenough.org</link>
	<description>… and there is much to be learned</description>
	<lastBuildDate>Mon, 19 Jul 2010 14:57:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>RESTful Service Discovery and Description</title>
		<link>http://barelyenough.org/blog/2008/01/restful-service-discovery-and-description/</link>
		<comments>http://barelyenough.org/blog/2008/01/restful-service-discovery-and-description/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 21:00:30 +0000</pubDate>
		<dc:creator>Peter Williams</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[web services]]></category>

		<guid isPermaLink="false">http://pezra.barelyenough.org/blog/2008/01/restful-service-discovery-and-description/</guid>
		<description><![CDATA[ There has been a great deal of discussion
regarding
RESTful
web service
description languages this week.  The debate is great
for the community but I think Steve Vinoski has it basically right


  never once — not even once — have I seen anyone develop a consuming
  application without relying on some form of human-oriented
  documentation for [...] ]]></description>
			<content:encoded><![CDATA[<p>There has been a great deal of discussion
<a href="http://www.tbray.org/ongoing/When/200x/2008/01/18/Service-Doc-as-Interface-Def">regarding</a>
<a href="http://www.25hoursaday.com/weblog/2008/01/17/MythRESTfulWebServicesDontNeedAnInterfaceDefinitionLanguage.aspx">RESTful</a>
<a href="http://home.badc.rl.ac.uk/lawrence/blog/2008/01/22/whither_service_descriptions">web</a> <a href="http://www.mnot.net/blog/2008/01/21/wadl_watching">service</a>
<a href="http://tomayko.com/weblog/2008/01/18/ws-vs-rest-sucks-nowadays">description</a> languages this week.  The debate is great
for the community but I think <a href="http://steve.vinoski.net/blog/2008/01/16/idls-vs-human-documentation/">Steve Vinoski has it basically right</a></p>

<blockquote>
  <p>never once — not even once — have I seen anyone develop a consuming
  application without relying on some form of human-oriented
  documentation for the service being consumed</p>
</blockquote>

<p>When you start writing an application that makes use of some services
you are not writing some sort of generic web services consumer.  You
are writing a consumer of one very specific web service and the
semantics of a service, as with everything else, turn out to be a lot
more complicated, subtle and interesting than the syntax.</p>

<p>Human-oriented documentation necessary because only human can
understand the really interesting parts of a service description.
Based on my experience, it also seems to be sufficient.  Sure we could
all jump on the full fledged service description language band wagon
but I don&#8217;t think that service consumers would get much, if any, value
out of it.<sup><a href="#footnote-where-the-value-is-8b1415153ca8378fe8dd5604f407c125" class="footnote-ref">1</a></sup></p>

<h2>Discoverability</h2>

<p>Discoverability is the most important capability that interface
definition languages bring to the table.  However, most service
description languages provide discoverability almost as a side effect,
rather than it being their primary purpose.</p>

<p>I think it would be better to promote discoverability by working on a
more focused capabilities publishing mechanism.  To that end, I want
to describe what my team has done on this front.  It is not entirely
suitable general use, but useful standards often emerge from
extracting the common parts of many bespoke solutions.</p>

<p>First I want to be clear about the terminology I am using just to make
sure we all understand one another</p>

<dl>
<dt>service</dt>
<dd>A cohesive set of resources that are exposed via HTTP.</dd>

<dt>resource</dt>
<dd>An single entity which exposes a RESTful interface via HTTP.</dd>

<dt>service provider</dt>
<dd>A process or set of processes that implement one or more 
services.</dd>

<dt>container</dt>
<dd>Another name for a service provider.</dd>
</dl>

<h4>Background</h4>

<p>We needed the ability to discover the actual URIs of resources at
runtime from very early in our project because of our basic
architecture.  Our system is composed of at least four
services<sup><a href="#footnote-some-times-more-8b1415153ca8378fe8dd5604f407c125" class="footnote-ref">2</a></sup>.  The containers that provide these
services may be deploy in various (and arbitrary) ways.  Maintaining
the list of top level resources of other services in configuration
files became unmanageable long before we every actually deployed the
system in production.</p>

<p>We need a way that any component in the system could discover the URIs
of resources exposed by other components in the system.  We handled
this by providing a system wide registry of all the services that are
available and a description resource for each service that provides
link to the resources contained with that service.</p>

<h3>Service Description</h3>

<p>Containers that provide a service are responsible for exposing a
&#8220;service description&#8221; for that service.</p>

<p>A service description is a resource that provides links to all the top
level resources in service.  Currently we support just one type of
representation (format) for service description, a JSON format that
looks like this</p>

<pre><code>{
  "_type":        "ServiceDescriptor",
  "service_type": "http://mydomain.example/services/something-interesting",
  "resources": [
    {
      "_type": "ResourceDescriptor",
      "name":  "OpenIdProvider",
      "href":  "http://core.ssbe.example/openid"
    },
    {
      "_type": "ResourceDescriptor",
      "name":  "AllAccounts",
      "href":  "http://core.ssbe.example/accounts"
    }
  ]
}
</code></pre>

<p><code>service_type</code> is the globally unique name for the type service that
is being described.  It should be a URI that is owned by the creator
of the service.  Each top level resource that is exposed as part of
this service has a resource descriptor in the <code>resources</code> set.</p>

<p>If you wanted know about all the accounts of the system you would</p>

<ol>
<li><code>GET</code> the service descriptor resource</li>
<li>iterate over the resources collection until you found the 
 <code>AllAccounts</code> resource descriptor</li>
<li><code>GET</code> the URI found in the <code>href</code> pair of the resource
 descriptor (<code>http://core.ssbe.example/accounts</code> in this example)</li>
</ol>

<p>One important thing to note is that each resource is really exactly
one resource, and not a type of resource.  If you are looking for a
particular account you have to get the AllAccounts collection and find
the account you are looking for in that set.</p>

<h3>Capabilities</h3>

<p>The Capabilities resource is the only well known entry point for our
system.  If a program wants to interact with our system it always
starts with the capabilities service and the works it&#8217;s way down,
using the links in documents, to the resource it actually cares about.</p>

<p>The JSON representation we support looks like</p>

<pre><code>{  
  "_type": "SystemCapabilities",
  "services": [
    {
      "_type":        "ServiceDescriptor",
      "href":         "http://alarm.ssbe.example/service_descriptors/escalations",
      "service_type": "http://mydomain.example/services/something-interesting"
    }
  ]
}
</code></pre>

<p>To discover the URI of a particular top level resource a consumer must</p>

<ol>
<li><code>GET</code> the capabilities document</li>
<li>iterate though the objects in <code>services</code> until if it finds the 
 one of the correct <code>service_type</code></li>
<li><code>GET</code> the full service descriptor using the URI in the <code>href</code> pair</li>
<li>iterate of the resources until it finds the one with the correct 
 name</li>
<li>extract the URI from it&#8217;s <code>href</code> pair</li>
</ol>

<p>Services are registered with the capabilities resource, by
<code>POST</code>ing a service description to it, when the containers that
provide those services are started.</p>

<h3>Issues</h3>

<h4>No supported methods or format information</h4>

<p>This approach only provides a way to discover the URIs of top level
resources.  It makes no attempt to describe the representations (formats) or
methods those resources support.  That sort of thing would not be hard add 
but so far I have had absolutely not need for it.  That information is provided 
by the human-oriented documentation and
since it does not change in each deployment there is no
need for it included in the dynamic resource discovery mechanism.</p>

<h4>Non-top level resources are not represented</h4>

<p>Resources that are not top level &#8212; by which I mean resources that not
listed in a service description document &#8212; are not represented at
all.  This is a feature, really, but it makes extending this format to
include method and data format information less compelling becayse only a
relatively minor subset of the resources in the system are surfaced in
the service descriptions.</p>

<h4>Encourages large representations</h4>

<p>The fact that only singleton resources are supported can lead to top
level documents that are excessively large.  In fact, we have already
had to deal with this issue.  We have basically punted on the issue but
I think the correct approach would be to introduce a
ResourceTypeDescriptor that would operate much like a
ResourceDescriptor except that the link would be a <a href="http://bitworking.org/projects/URI-Templates/">URI template</a>
rather than a concrete URI.</p>

<ol class="footnotes">
<li id="footnote-where-the-value-is-8b1415153ca8378fe8dd5604f407c125">
<p>On the other hand service providers might get
some value.  Something like WADL does give you a way to declaratively
define a suite of regression tests.  On the other hand, you might be
better off using a tool specifically built for that purpose.</p>
</li>
<li id="footnote-some-times-more-8b1415153ca8378fe8dd5604f407c125">
<p>That is the base number of services.  Additionally
functionality is added to the system in the form of additional
services so the actually number of services varies based on what you
need the system to do.</p>
</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://barelyenough.org/blog/2008/01/restful-service-discovery-and-description/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
