<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet href="http://duncan-cragg.org/css/atom.css" type="text/css" ?>
<!-- Copyright (c) 2006 Duncan Cragg -->

<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
    <id>http://duncan-cragg.org/blog/</id>
    <title>What Not How - Posts tagged 'forest'</title>
    <subtitle>Duncan Cragg on Declarative Architectures</subtitle>
    <author><name>Duncan Cragg</name></author>
    <logo>/favicon.gif</logo>
    <icon>/favicon.ico</icon>
    <rights>All content including photos and images by Duncan Cragg. Copyright (c) Duncan Cragg, your rights preserved: see /CXL.html</rights>
    <generator uri="http://www.djangoproject.com">A Django Production.</generator>
    <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/" title="What Not How" />
    <link rel="self" type="application/atom+xml" href="http://duncan-cragg.org/blog/atom/forest/" />

    <updated>2010-03-18T16:58:00Z</updated>


    <entry>
        <id>http://duncan-cragg.org/blog/post/json-mash/</id>
        <title>JSON-Mash</title>
        <published>2010-03-18T16:58:00Z</published>
        
        <updated>2010-03-18T16:58:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/json-mash/" title="JSON-Mash" />
        
        <category term="declarative" />
        
        <category term="event-driven" />
        
        <category term="rest" />
        
        <category term="json" />
        
        <category term="rest-observer" />
        
        <category term="forest" />
        
        <category term="fjord" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Around the middle of February I completed a basic persistence and networking
implementation for
<a href="http://duncan-cragg.org/blog/post/fjord-in-memory/">Fjord</a>,
then had to do other things for a month.  Just recently I
fixed Fjord to work with the latest version of the 
<a href="http://nodejs.org/">Node.js</a> APIs.
</p><p>
Next project: I&#39;m going to use Fjord in a Web Framework to be called &quot;JSON-Mash&quot;.
</p><p>
I intend to show that JSON-Mash will be a great framework for rapidly building
truly interoperable and truly scalable online and distributed functionality.
</p><p>
Here&#39;s how JSON-Mash will work.
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Around the middle of February I completed a basic persistence and networking
implementation for
<a href="http://duncan-cragg.org/blog/post/fjord-in-memory/">Fjord</a>,
then had to do other things for a month.  Just recently I
fixed Fjord to work with the latest version of the 
<a href="http://nodejs.org/">Node.js</a> APIs.
</p><p>
Next project: I&#39;m going to use Fjord in a Web Framework to be called &quot;JSON-Mash&quot;.
</p><p>
I intend to show that JSON-Mash will be a great framework for rapidly building
truly interoperable and truly scalable online and distributed functionality.
</p><p>
Here&#39;s how JSON-Mash will work.
</p></div><p>
<b>Juggling Data Formats</b>
</p><p>
In traditional Web Frameworks, the developer has to juggle up to five different data
formats. 
</p><p>
At the front end, you may be working in HTML or HTML chunks sent via Ajax. Then your
domain logic may use object classes. You&#39;ll no doubt map those objects to relations in
your database layer. That&#39;s three data representations (also known as
<a href="http://research.microsoft.com/en-us/um/people/emeijer/papers/xml2003/xml2003.html">Circles, Triangles and Rectangles</a>).
</p><p>
But there may be even more: if you call out to integration points such as a search
service or other API, you&#39;ll probably be using XML. And if you did application-level
cacheing, you would probably consider casting your data into key-value form.
</p><p>
This is not unrealistic - at a current ThoughtWorks client, I was faced with exactly
these five data formats - in an extremely simple application.
</p><p>&#160;</p><p>
<b>JSON Everywhere</b>
</p><p>
JSON-Mash will do away with all that. It uses JSON objects everywhere. 
</p><p>
JSON-Mash sends JSON data to a script in the browser that builds the page declaratively
from its understanding of a number of stable, generic JSON types. It uses Ajax and Comet
to pull JSON chunks in, to composite into the page.
</p><p>
JSON-Mash uses Fjord to process its JSON: transforms, map-reduce, etc. It uses Fjord to
persist objects in a JSON NoSQL database, and Fjord to provide shared JSON cacheing
functionality with cache updating via Fjord&#39;s
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">FOREST</a>
integration style.
</p><p>
Finally, if there&#39;s any external system to be integrated, that too will be accessed via
an adaptor that converts its API, etc., into JSON-Mash stabilised JSON. There will be
Twitter and Flickr adaptors at first, I should imagine.
</p><p>&#160;</p><p>
<b>JSON-Mash and Fjord</b>
</p><p>
Using Fjord means that JSON-Mash treats its JSON as a first-class hyperdata type: lots
of little JSON chunks all with URLs and all linked up. I 
<a href="http://duncan-cragg.org/blog/post/introducing-fjord/">suggested</a>
that one day it may have the media type of &quot;<code>application/fjord+json</code>&quot;.  JSON-Mash Nodes
communicate in the 
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">FOREST</a>
style.
</p><p>
Of course, the main benefit of using Fjord is that you get a great, declarative mashup
language to describe your logic in. 
</p><p>
Fjord is still very new, of course, so some goodness is yet to be rounded out. For
example, it comes with a very basic, but highly improvable, NoSQL JSON datastore and
already allows some powerful map-reduce and other query and transformation modes, with
more to come.
</p><p>
Finally, Fjord gives a dynamic view of JSON data: caches get updates pushed into them
and Comet pull will also come as part of the package.
</p><p>&#160;</p><p>
<b>CSI and SSI</b>
</p><p>
Now, one of the great things about Node.js is that you can run the same code on the
server as you run in the browser.
</p><p>
My previous attempts at doing things the JSON-Mash way have met with some resistance
when I suggested building duplicate logic server-side to render pages statically, for
accessibility and search engines. 
</p><p>
But with Node, this problem goes away: you can use the exact same Javascript to convert
JSON to HTML on the server side as you do on the browser.
</p><p>
I use the phrases &#39;Client-Side Include&#39; and &#39;Server-Side Include&#39; or CSI and SSI as
easily-understood shorthand for this kind of page assembly from JSON elements.
</p><p>
Settling on a number of stable JSON types means that - once the types and their
rendering are stable and coded - you never need to write any Javascript yourself in
JSON-Mash. It&#39;s all done declaratively, and looks the same whether generated by an SSI
Node or the CSI in the browser. For example, you can trigger calendars and maps in the
browser view, with just small JSON declarations.
</p><p>
This approach differs from &quot;progressive enhancement&quot; as long as you have both full CSI
and full SSI to render your site. But you could also have a &#39;CSI-SSI slider&#39;, where an
initial page is generated by SSI, then CSI takes over to fill in the funky stuff: the
dynamic widgets and Comet-driven elements.
</p><p>&#160;</p><p>
<b>Users Exploring a Dynamic Web of JSON</b>
</p><p>
The way JSON-Mash works is that you get a view into a hyperlinked Web of JSON data, and
can explore it from any point outwards. In the CSI version, each JSON chunk is loaded
lazily as it is encountered, then reloaded when it changes.  Even the SSI version of the
site would allow this form of exploration, although in a less efficient and dynamic way,
of course. 
</p><p>
In JSON-Mash, the user is also a first-class object; the stable JSON types also include
a type representing the user. This user is driving their browser, subscribing to events
on visible JSON page components via Comet, and POSTing their own user state to a
server-side cache copy.
</p><p>
Hence, if that user state contains a message, you can get simple chat functionality,
without any code, just by linking to a user and viewing them.
</p><p>&#160;</p><p>
<b>Conclusion</b>
</p><p>
JSON-Mash is a Web Framework that will use, re-use, assemble, mash, transform, store,
share, push, pull and render JSON from end to end and top to bottom; from Ajax to NoSQL.
</p><p>
Most domain-logic programming will be done in simple, powerful declarative functions,
with adaptors, drivers or renderers written in Javascript for Node.js or the browser.
Cross-host exchange is done in the FOREST style.
</p><p>
SSI or CSI page assembly are very flexible ways of mashing up new functionality from multiple
back-end sources of RESTfully-sourced, interlinked JSON data.  And with cache updates
telling SSI and CSI when the back-end data has changed, you get a very dynamic yet
scalable system.
</p><p>
JSON-Mash will be a framework for rapidly building truly interoperable and truly
scalable online and distributed functionality. 
</p><p>
I&#39;ll write more on the benefits once I&#39;ve got some code to prove it!  Follow me on 
<a href="http://twitter.com/duncancragg">Twitter</a>
and I&#39;ll let you know when I&#39;ve got something up on 
<a href="http://github.com/duncancragg">GitHub</a>.

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/fjord-in-memory/</id>
        <title>Fjord in Memory</title>
        <published>2010-01-26T13:46:00Z</published>
        
        <updated>2010-01-26T13:46:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/fjord-in-memory/" title="Fjord in Memory" />
        
        <category term="json" />
        
        <category term="forest" />
        
        <category term="fjord" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Right, I&#39;m pleased to say that I&#39;ve now implemented enough of the 
<a href="http://duncan-cragg.org/blog/post/fjord-node/">Fjord language</a>
on <a href="http://nodejs.org/">Node.js</a> to be able to run the 
<a href="http://duncan-cragg.org/blog/post/introducing-fjord/">Instrument example</a>
that I introduced it with.  As yet, this runs in memory only - i.e., no disk, no
network.
</p><p>
<a href="http://github.com/DuncanCragg/Fjord/">Here&#39;s the code on GitHub</a> with tests
that show how it works. The language has changed a little so I&#39;ll show the example here
again, copied over from the test code, in order to explain the differences.
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Right, I&#39;m pleased to say that I&#39;ve now implemented enough of the 
<a href="http://duncan-cragg.org/blog/post/fjord-node/">Fjord language</a>
on <a href="http://nodejs.org/">Node.js</a> to be able to run the 
<a href="http://duncan-cragg.org/blog/post/introducing-fjord/">Instrument example</a>
that I introduced it with.  As yet, this runs in memory only - i.e., no disk, no
network.
</p><p>
<a href="http://github.com/DuncanCragg/Fjord/">Here&#39;s the code on GitHub</a> with tests
that show how it works. The language has changed a little so I&#39;ll show the example here
again, copied over from the test code, in order to explain the differences.
</p></div><p>
Starting with the instrument rules:
</p><pre>
inrl1=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                       &#39;  &quot;%owid&quot;: &quot;/$this/&quot;,&#39;+
                       &#39;  &quot;%refs&quot;: { &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],&#39;+
                       &#39;             &quot;%owid&quot;: &quot;/$bid/&quot;,&#39;+
                       &#39;             &quot;on&quot;: &quot;/$this/&quot; },&#39;+
                       &#39;  &quot;buyers&quot;: &quot;/array/has($bid)/&quot; }&#39;);
// -------------------------------------------------------------------
inrl2=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                       &#39;  &quot;%owid&quot;: &quot;/$this/&quot;,&#39;+
                       &#39;  &quot;%refs&quot;: { &quot;tags&quot;: [ &quot;equity&quot;, &quot;ask&quot; ],&#39;+
                       &#39;             &quot;%owid&quot;: &quot;/$ask/&quot;,&#39;+
                       &#39;             &quot;on&quot;: &quot;/$this/&quot; },&#39;+
                       &#39;  &quot;sellers&quot;: &quot;/array/has($ask)/&quot; }&#39;);
</pre><p>
These are the rules that add - or, rather, ensure the presence of - referring bids and
asks in the instrument&#39;s buyers and sellers lists. The big difference here is that
referrers are now accessed through the &#39;%refs&#39; tag. Both &#39;%refs&#39; and &#39;%owid&#39; are
available on all Fjord objects: %owid is the Object Web ID of the object, and %refs has
a list of the OWIDs of all currently referring objects.
</p><p>
But, of course, you can&#39;t see the list or the OWIDs under %refs! This rule shows how
Fjord can match single items to lists of items, and how it transparently jumps any OWIDs
it comes across, to continue matching. In this case there is a pattern for a bid or ask
object that refers to the instrument - notice the  &quot;on&quot;: &quot;/$this/&quot; match. 
</p><p>
Every object in %refs must have some such link to the referred-to object that triggered
the referral in the first place. This referrer becomes an observer: its rules are run
again if any object it refers to changes.
</p><p>
More instrument rules:
</p><pre>
inrl3=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                       &#39;  &quot;buyers&quot;:  { &quot;price&quot;: &quot;/$bids;number/&quot; },&#39;+
                       &#39;  &quot;bid-ask-spread&quot;: { &quot;high-bid&quot;: &quot;/number/max($bids)/&quot; } }&#39;);
// -------------------------------------------------------------------
inrl4=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                       &#39;  &quot;sellers&quot;: { &quot;price&quot;: &quot;/$asks;number/&quot; },&#39;+
                       &#39;  &quot;bid-ask-spread&quot;: { &quot;low-ask&quot;:  &quot;/number/min($asks)/&quot; } }&#39;);
</pre><p>
These are the rules that set the bid-ask-spread of the instrument from the prices of the
bids or asks in each list. It shows how, when a single match instance binds to a list,
it can give a match set in any bound variables - here, &#39;$bids&#39; and &#39;$asks&#39; - which can
then be reduced - here, using &#39;max()&#39; and &#39;min()&#39;.
</p><p>
The rules are now separated into two, as there was a historic <i>first ever bug in
public Fjord code</i>: the original rule wouldn&#39;t match unless at least one buyer <i>and</i>
one seller were present, and we&#39;re adding them one by one from scratch this time!
</p><p>
Here is the actual instrument object:
</p><pre>
inst=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                      &#39;  &quot;long-name&quot;: &quot;Acme Co., Inc&quot;,&#39;+
                      &#39;  &quot;buyers&quot;: [ ],&#39;+
                      &#39;  &quot;sellers&quot;: [ ],&#39;+
                      &#39;  &quot;bid-ask-spread&quot;: { &quot;high-bid&quot;: &quot;10.0&quot;, &quot;low-ask&quot;:  &quot;20.0&quot; } }&#39;,
                      [ inrl1, inrl2, inrl3, inrl4 ] );
</pre><p>
Notice the list of rules that the object will be animated by: inrl1, etc., which are the
rule object OWIDs, not the actual rule objects. The bid-ask-spread is set to some seed values.
</p><p>
On to bid and ask rules:
</p><pre>
bidrule=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],&#39;+
                         &#39;  &quot;on&quot;: { &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                         &#39;          &quot;bid-ask-spread&quot;: { &quot;high-bid&quot;: &quot;/$hibid;number/&quot; } },&#39;+
                         &#39;  &quot;price&quot;: &quot;/null/fix(2, $hibid * 1.10 )/&quot; }&#39;);
// -------------------------------------------------------------------
askrule=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;ask&quot; ],&#39;+
                         &#39;  &quot;on&quot;: { &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                         &#39;          &quot;bid-ask-spread&quot;: { &quot;low-ask&quot;: &quot;/$loask;number/&quot; } },&#39;+
                         &#39;  &quot;price&quot;: &quot;/null/fix(2, $loask * 0.90 )/&quot; }&#39;);
</pre><p>
Here we have rules for setting the price of a bid or an ask as a ratio of the
instrument&#39;s bid-ask-spread numbers. These are not meant to be realistic business rules
of course - they&#39;re for illustration purposes. The only real difference here is fixing
the result to 2 decimal places, since Javascript was adding ugly rounding errors.
</p><p>
Now we go ahead and create two bids and two asks, pointing at the instrument by simply 
including its OWID:
</p><pre>
bid1=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ], &quot;on&quot;: &quot;&#39;+inst+&#39;&quot;, &quot;price&quot;: &quot;&quot; }&#39;, [ bidrule ]);
bid2=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ], &quot;on&quot;: &quot;&#39;+inst+&#39;&quot;, &quot;price&quot;: &quot;&quot; }&#39;, [ bidrule ]);
ask1=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;ask&quot; ], &quot;on&quot;: &quot;&#39;+inst+&#39;&quot;, &quot;price&quot;: &quot;&quot; }&#39;, [ askrule ]);
ask2=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;ask&quot; ], &quot;on&quot;: &quot;&#39;+inst+&#39;&quot;, &quot;price&quot;: &quot;&quot; }&#39;, [ askrule ]);
</pre><p>
This fires off all the rules and notifications .. and rules and notifications .. giving
the final result:
</p><pre>
exp=new WebObject(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                  &#39;  &quot;long-name&quot;: &quot;Acme Co., Inc&quot;,&#39;+
                  &#39;  &quot;buyers&quot;:  [ &quot;&#39;+bid1+&#39;&quot;, &quot;&#39;+bid2+&#39;&quot; ],&#39;+
                  &#39;  &quot;sellers&quot;: [ &quot;&#39;+ask1+&#39;&quot;, &quot;&#39;+ask2+&#39;&quot; ],&#39;+
                  &#39;  &quot;bid-ask-spread&quot;: { &quot;high-bid&quot;: &quot;12.1&quot;, &quot;low-ask&quot;:  &quot;16.2&quot; } }&#39;)
// -------------------------------------------------------------------
test.objectsEqual(&quot;Instrument example works&quot;, Cache[inst], exp);
</pre><p>
Here the buyers and sellers correctly list the referring bids and asks, and the
bid-ask-spread has been set to the values you get after two ratios are applied to the
original seed numbers.
</p><p>
Rewrite rules are run on object construction, they&#39;re run whenever an object has a new
referrer in its &#39;refs&#39; list, and also whenever another object that&#39;s being referred to
changes. The latter isn&#39;t exercised in this example, as all events are propagated by
referral alone. The tests of Fjord have examples of the full Observer Pattern in operation.
</p><p>&#160;</p><p>
<b>Next Up</b>
</p><p>
Now, this is living code, so it will no doubt be different again, soon. Watch this space, and
<a href="http://twitter.com/duncancragg">follow me on Twitter</a>, to keep up to date with developments.
</p><p>
Next, I&#39;ll be working on simple disk persistence of Fjord JSON objects and rules,
followed by distribution in the 
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">FOREST</a> style...

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/fjord-node/</id>
        <title>Fjord in Node</title>
        <published>2010-01-06T17:03:00Z</published>
        
        <updated>2010-01-06T17:03:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/fjord-node/" title="Fjord in Node" />
        
        <category term="event-driven" />
        
        <category term="json" />
        
        <category term="forest" />
        
        <category term="fjord" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Well, I&#39;ve put together the first few lines of <a href="http://duncan-cragg.org/blog/post/introducing-fjord/">Fjord</a>, implemented on <a href="http://nodejs.org/">Node.js</a>.
</p><p>
Here&#39;s the description on <a href="http://github.com/DuncanCragg/Fjord">GitHub</a>: <i>Fjord is a language for expressing domain logic as match-rewrite functions over mashable JSON Web objects</i>.
</p><p>
I&#39;m developing Fjord very openly, in the hope someone out there will be interested in getting involved in helping guide its design and implementation. I suppose code speaks louder than blog posts.
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Well, I&#39;ve put together the first few lines of <a href="http://duncan-cragg.org/blog/post/introducing-fjord/">Fjord</a>, implemented on <a href="http://nodejs.org/">Node.js</a>.
</p><p>
Here&#39;s the description on <a href="http://github.com/DuncanCragg/Fjord">GitHub</a>: <i>Fjord is a language for expressing domain logic as match-rewrite functions over mashable JSON Web objects</i>.
</p><p>
I&#39;m developing Fjord very openly, in the hope someone out there will be interested in getting involved in helping guide its design and implementation. I suppose code speaks louder than blog posts.
</p></div><p>
It&#39;s going to be slow progress, with a wife, two kids, and Thoughtworks all together getting 99% of my life, but at least people will be able to keep up with what I&#39;m trying to do... I only got the project started at all because I&#39;m off sick right now!
</p><p>
Here&#39;s the GitHub link: <a href="http://github.com/DuncanCragg/Fjord">http://github.com/DuncanCragg/Fjord</a>.
</p><p>
Follow me on Twitter if you want all the latest news .. <a href="http://twitter.com/duncancragg">http://twitter.com/duncancragg</a>
</p><p>
Oh - I was lying about FOREST being GET-only, that was just to engage the REST community, but since I got zero reaction from anyone I may as well admit that I intended FOREST to use POST all along - to push updated resources into subscriber caches as I have always done. Or to use long-GETs to pull them in. Both are tunnelling cache refreshes over HTTP. Neither are Official REST.
</p><p>
Cheers!

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/introducing-fjord/</id>
        <title>Introducing Fjord</title>
        <published>2009-12-11T08:22:00Z</published>
        
        <updated>2009-12-11T08:22:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/introducing-fjord/" title="Introducing Fjord" />
        
        <category term="declarative" />
        
        <category term="json" />
        
        <category term="forest" />
        
        <category term="fjord" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Following on from my recent article where I
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">derived FOREST</a>,
this article offers the beginnings of a JSON unification and rewriting language that
can be used in a FOREST architecture.
</p><p>
Why JSON, not XHTML, now? Well, I recently discovered that
<a href="http://www.google.com/trends?q=json%2C+xhtml">JSON is overtaking XHTML</a>
in interest, and I was further inspired by Kris Zyp&#39;s recent announcement of his
<a href="http://www.ietf.org/id/draft-zyp-json-schema-01.txt">JSON Schema</a>
Internet-Draft.
</p><p>
Fjord is a language for describing how the state of a JSON resource at any time depends
on both its current state and on the state of other JSON resources that it links to via
hyperlinks.  
</p><p>
Fjord is a Norwegian word, probably pronounced &#39;fiyourd&#39;, and might stand for some
combination of the words: &#39;Functional JSON Object/Observer Resource/Rule/Rewrite
Dependencies/Declarations&#39;. Or maybe it&#39;s just because they&#39;re
<a href="http://images.google.co.uk/images?q=fjord">truly awesome</a>, an&#39; I wanna go.
</p><p>
Fjord also gives me an opportunity to show some examples of the &quot;end-user&quot; view of a FOREST
interaction; starting with a simple finance example.
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Following on from my recent article where I
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">derived FOREST</a>,
this article offers the beginnings of a JSON unification and rewriting language that
can be used in a FOREST architecture.
</p><p>
Why JSON, not XHTML, now? Well, I recently discovered that
<a href="http://www.google.com/trends?q=json%2C+xhtml">JSON is overtaking XHTML</a>
in interest, and I was further inspired by Kris Zyp&#39;s recent announcement of his
<a href="http://www.ietf.org/id/draft-zyp-json-schema-01.txt">JSON Schema</a>
Internet-Draft.
</p><p>
Fjord is a language for describing how the state of a JSON resource at any time depends
on both its current state and on the state of other JSON resources that it links to via
hyperlinks.  
</p><p>
Fjord is a Norwegian word, probably pronounced &#39;fiyourd&#39;, and might stand for some
combination of the words: &#39;Functional JSON Object/Observer Resource/Rule/Rewrite
Dependencies/Declarations&#39;. Or maybe it&#39;s just because they&#39;re
<a href="http://images.google.co.uk/images?q=fjord">truly awesome</a>, an&#39; I wanna go.
</p><p>
Fjord also gives me an opportunity to show some examples of the &quot;end-user&quot; view of a FOREST
interaction; starting with a simple finance example.
</p></div><p>
<b>Instrument, Bids, Asks</b>
</p><p>
Let&#39;s take the simplest possible view of a
<a href="http://www.livemint.com/2009/04/05215410/Ask-Mint--Bidask-spread-all.html">financial market</a>.
</p><p>
There&#39;s an Instrument, and there are Bids and Asks on that Instrument. The Instrument
summarises all the Bids and Asks into the &#39;bid-ask spread&#39;, taking the highest bid price
and the lowest ask price.  Forget volumes, trades and any other detail. 
</p><p>
The Instruments, Bids and Asks are on various servers across various organisations.
That&#39;s the &#39;symmetric REST&#39; part.
</p><p>
Here&#39;s a JSON Instrument resource at the URL shown. It holds three Bid or Ask objects:
</p><pre>
http://the-bank.com/fjord/equity-instrument-23ab33-2319f.json
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],
    &quot;long-name&quot;: &quot;Acme Co., Inc&quot;,
    &quot;buyers&quot;: [ 
        &quot;@http://a-bank.com/fjord/equity-bid-9ac0d1-88ce1.json&quot;
    ],
    &quot;sellers&quot;: [ 
        &quot;@http://c-bank.com/fjord/equity-ask-510efb-cca62.json&quot;,
        &quot;@http://d-bank.com/fjord/equity-ask-8560ae-33eff.json&quot;
    ],
    &quot;bid-ask-spread&quot;: {
        &quot;high-bid&quot;: &quot;10.00&quot;,
        &quot;low-ask&quot;:  &quot;14.00&quot;
    }
}
</pre><p>
The &#39;@&#39; character is the flag that this string is a link or a URL.  The meaningful names
in those links are really just for humans and the layers below us - Fjord itself won&#39;t
let you see inside them.
</p><p>
</p><blockquote class="others-content"><div><p>
So now that we&#39;ve introduced a JSON extension making it a hypermedia or hyperdata
type, perhaps we should announce this convention in a media type string. How about 
&quot;<code>application/fjord+json</code>&quot;?  This media type will also serve to set expectations on
everything else about Fjord JSON objects, once the notation is stable.
</p></div></blockquote><p>
</p><p>
Notice that, instead of &#39;class&#39; or &#39;type&#39; or a top-level tag, we have a list of tags.
In Fjord, class is in the eye of the beholder - but, of course, must be a stable grammar
in the eye of the generator!
</p><p>
Right, so here is a new Bid object held at &#39;B&#39; Bank, that the Instrument hasn&#39;t seen yet:
</p><pre>
http://b-bank.com/fjord/equity-bid-0043ee-419ac.json
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],
    &quot;on&quot;: &quot;@http://the-bank.com/fjord/equity-instrument-23ab33-2319f.json&quot;,
    &quot;price&quot;: &quot;&quot;,
    &quot;by&quot;: &quot;@http://b-bank.com/fjord/hcard-b-bank-4990cd-232b0.json&quot;
}
</pre><p>
It has a pointer to the Instrument it is a bid on, a bid price that isn&#39;t yet set, and a
link to the hCard object of the bank offering the bid and serving this Bid object.
</p><p>
So Bids and Asks can see Instruments and vice-versa, and each can set their own state
accordingly, as part of a FOREST interaction.
</p><p>
The &#39;animation&#39; of Bid, Ask and Instrument JSON object resources is driven by three
simple Fjord rules...
</p><p>&#160;</p><p>
<b>Rule One: Bid Sets Price From Instrument</b>
</p><p>
Here is a rule setting the price of a new Bid to be 10% more than the highest current
Bid on the instrument, hopefully ensuring this Bid is now the high bid:
</p><pre>
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],
    &quot;on&quot;: { &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],
            &quot;bid-ask-spread&quot;: { &quot;high-bid&quot;: &quot;/$hibid;decimal/&quot; }
          },
    &quot;price&quot;: &quot;/null/( $hibid * 1.10 )/&quot;
}
</pre><p>
This is a template that matches the Bid object and its dependencies and rewrites part of
the Bid.
</p><p>
<i>Notice how the Bid object&#39;s link to the Instrument object is jumped transparently: the
Bid can &#39;see&#39; right into the Instrument in order to do its matching.  However, it cannot
itself rewrite the Instrument - only Instrument rules can do that.</i>
</p><p>
In Fjord, matching is written with the &#39;/ ; /&#39; notation: each part of this
semicolon-separated list must match. In this case, the high bid has to bind to the
identifier &#39;$hibid&#39; and has to be a decimal. The price must not be set yet. 
</p><p>
The keys &#39;decimal&#39; and &#39;null&#39; are, of course, special reserved words for matching in
patterns.  The &#39;null&#39; matches empty strings, lists and hashes.
</p><p>
The rewrite part follows at the end of a match and is also wrapped in slashes. Here, the
price is being set to the high-bid plus 10%.  The parentheses introduce an expression.
</p><p>
This rule only matches if the price is empty - once set, the rule will not refire.
</p><p>
For more complex rewrites, the following forms can also be used: 
</p><pre>
    &quot;price&quot;: { &quot;/null//&quot;: &quot;( $hibid * 1.10 )&quot; }
    &quot;price&quot;: { &quot;when&quot;: &quot;/null/&quot;, &quot;then&quot;: &quot;( $hibid * 1.10 )&quot; }
</pre><p>
which allow full hashes and lists to be both matched and set.
</p><p>&#160;</p><p>
<b>Rule Two: Instrument Puts New Bid into its Buyers List</b>
</p><p>
The Instrument adds the new Bid to its buyers list with this rule:
</p><pre>
{   &quot;#url&quot;: &quot;/$bid/&quot;,
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],
    &quot;on&quot;: { &quot;#url&quot;: &quot;/this/&quot;,
            &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],
            &quot;buyers&quot;: &quot;/list/has($bid)/&quot;,
    }
}
</pre><p>
This is a rule on the Instrument, that &#39;looks up to&#39; and matches the enclosing Bid.
</p><p>
The &#39;#url&#39; is an optional, reserved-word entry that can only appear at the top of a JSON
resource and holds that resource&#39;s URL. Here, it is bound to &#39;$bid&#39;, picking up the URL
of the Bid object that refers to and encloses this Instrument.
</p><p>
Further down, the &quot;#url&quot; reserved-word value of &quot;this&quot; indicates the start of the
object that this rule applies to. If &quot;this&quot; is absent, then, of course, this is a rule
on the top-level object, as in the first rule above.
</p><p>
The rewrite part matches the buyers list of the Instrument and applies the &#39;has()&#39;
operator which ensures the list now contains the wrapping Bid; it rewrites the list to
include its argument if it doesn&#39;t already. 
</p><p>
If this rule matches two wrapping Bids simultaneously, then &#39;$bid&#39; is set to a &#39;match
set&#39; - a simultaneous binding to the URLs of all of those Bids, and &#39;has()&#39; must ensure
that all of these Bids are now in the list at once.
</p><p>
If there is no change after a rule is applied, the resource&#39;s Etag isn&#39;t incremented, and
dependent rules won&#39;t fire. <i>Fjord may re-apply any rule at any time, usually on an
incoming state change indicated by Etag, so matches have to be designed accordingly.</i>
</p><p>
That&#39;s why we say &#39;has&#39;, not &#39;add&#39;, which would add the Bid again and again each time
the rule is applied. We could say <code>&quot;/list;hasNo($bid)/add($bid)/&quot;</code>, but that&#39;s
uglier and more imperative than declarative.
</p><p>&#160;</p><p>
<b>Rule Three: Instrument Sets Bid-Ask Spread from Bids and Asks</b>
</p><p>
This is what the instrument looks like, now, with the new link to our Bid:
</p><pre>
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],
    &quot;long-name&quot;: &quot;Acme Co., Inc&quot;,
    &quot;buyers&quot;: [ 
        &quot;@http://a-bank.com/fjord/equity-bid-9ac0d1-88ce1.json&quot;,
        &quot;@http://b-bank.com/fjord/equity-bid-0043ee-419ac.json&quot;
    ],
    &quot;sellers&quot;: [ 
        &quot;@http://c-bank.com/fjord/equity-ask-510efb-cca62.json&quot;,
        &quot;@http://d-bank.com/fjord/equity-ask-8560ae-33eff.json&quot;
    ],
    &quot;bid-ask-spread&quot;: {
        &quot;high-bid&quot;: &quot;10.00&quot;,
        &quot;low-ask&quot;:  &quot;14.00&quot;
    }
}
</pre><p>
And here is what the new B-Bank Bid looks like with its competitive price:
</p><pre>
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],
    &quot;on&quot;: &quot;@http://the-bank.com/fjord/equity-instrument-23ab33-2319f.json&quot;,
    &quot;price&quot;: &quot;11.00&quot;,
    &quot;by&quot;: &quot;@http://b-bank.com/fjord/hcard-b-bank-4990cd-232b0.json&quot;
}
</pre><p>
So now the Instrument has to adjust its bid-ask spread to accomodate the new Bid. This
happens when the following rule matches, which it always does - but only fires when a
change is detected:
</p><pre>
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],
    &quot;buyers&quot;:  { &quot;price&quot;: &quot;/$bids;decimal/&quot; },
    &quot;sellers&quot;: { &quot;price&quot;: &quot;/$asks;decimal/&quot; },
    &quot;bid-ask-spread&quot;: {
        &quot;high-bid&quot;: &quot;/decimal/max($bids)/&quot;,
        &quot;low-ask&quot;:  &quot;/decimal/min($asks)/&quot;
    }
}
</pre><p>
This rule matches as many times as there are Bids and Asks, meaning that the local
identifiers $bids and $asks are each bound to match sets. 
</p><p>
Notice how the &#39;{ price .. }&#39; patterns match elements of a list, in the same way an
XPath can match either one or several elements in a sequence of XML elements.
</p><p>
The &#39;max()&#39; and &#39;min()&#39; operators take the highest and lowest values in a match set
(or in a physical list, come to that). Once again, this rewrite means &#39;set this value
and increment the Etag, but only if there&#39;s a change&#39;. 
</p><p>
Here, the high-bid becomes our new Bid&#39;s &#39;11.00&#39;.
</p><p>&#160;</p><p>
<b>Fjord</b>
</p><p>
So that&#39;s a quick intro to some of my ideas for JSON matching and rewriting in a FOREST
architecture.
</p><p>
Fjord is a declarative, JSON-encoded language for expressing how the state of a JSON
resource is a function of both its own state and the state of peer JSON resources that
it can see via links in a hyperdata Web.
</p><p>
Fjord objects are &#39;masters of their own destiny&#39;, not allowing other objects to tell
them what to do except via declarative intention.
</p><p>
Further articles will give more proposals for the syntax and semantics of Fjord,
including true unification, and put it into the set of languages that are ideal for
programming parallel and distributed systems, as well as for integration.
</p><p>
Since Fjord is very young and I&#39;m still implementing it (in Java), I would certainly
welcome comments about it, or about the 
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">FOREST</a>
style that it supports. You can chat with me on 
<a href="http://twitter.com/duncancragg">Twitter</a>, too!

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/deriving-forest/</id>
        <title>Deriving FOREST</title>
        <published>2009-11-25T21:29:00Z</published>
        
        <updated>2009-11-25T21:29:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/deriving-forest/" title="Deriving FOREST" />
        
        <category term="architecture" />
        
        <category term="app" />
        
        <category term="microformats" />
        
        <category term="rest" />
        
        <category term="atom" />
        
        <category term="forest" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Say we want to integrate multiple applications which handle order processing. OK, that&#39;s
got to be one of the dullest starts to a blog post. Never mind, bear with me...
</p><p>
So, we have applications on separate servers for handling and driving data such as
orders, product descriptions and catalogues, stock lists, price lists, tracking, packing
notes and delivery notes, invoices, payments, etc.
</p><p>
We may choose an SOA approach, of course. But let&#39;s say our sponsors have heard of this
cheaper alternative: REST! Which to them means &#39;using Web technology to save money&#39;.
</p><p>
Now .. suppose we push the time slider right back to before Mark Baker and the SOA -vs-
REST Wars - or the &#39;SOAP -vs- REST Wars&#39; as people naively called it. To when REST was
simply (!) a description of the Web&#39;s architectural style...
</p><p>
What if we revisit the applicability of the Web, and its abstraction into REST, to the
architecture of machine-to-machine distributed systems - to something like our order
processing integration?
</p><p>
I think we&#39;d quickly arrive at something that looks more like
<a href="http://duncan-cragg.org/blog/post/forest-get-only-rest-integration-pattern/">FOREST</a>
than, say, AtomPub...
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Say we want to integrate multiple applications which handle order processing. OK, that&#39;s
got to be one of the dullest starts to a blog post. Never mind, bear with me...
</p><p>
So, we have applications on separate servers for handling and driving data such as
orders, product descriptions and catalogues, stock lists, price lists, tracking, packing
notes and delivery notes, invoices, payments, etc.
</p><p>
We may choose an SOA approach, of course. But let&#39;s say our sponsors have heard of this
cheaper alternative: REST! Which to them means &#39;using Web technology to save money&#39;.
</p><p>
Now .. suppose we push the time slider right back to before Mark Baker and the SOA -vs-
REST Wars - or the &#39;SOAP -vs- REST Wars&#39; as people naively called it. To when REST was
simply (!) a description of the Web&#39;s architectural style...
</p><p>
What if we revisit the applicability of the Web, and its abstraction into REST, to the
architecture of machine-to-machine distributed systems - to something like our order
processing integration?
</p><p>
I think we&#39;d quickly arrive at something that looks more like
<a href="http://duncan-cragg.org/blog/post/forest-get-only-rest-integration-pattern/">FOREST</a>
than, say, AtomPub...
</p></div><p>
Some pretty obvious things to notice about the Web and, indeed, REST:
</p><ul>
<li>The Web is essentially data on URLs of standard content types containing more URLs;</li>
<li>The Web is the Web because of the massive proliferation of links in that data;</li>
<li>REST mostly concerns itself with the consequences of GET, including cacheing;</li>
<li>The Web uses, I don&#39;t know, let&#39;s say 98% GET, 2% POST, around 0% other methods.</li>
</ul><p>
In other words, the Web, and its good qualities, are mostly based on:
</p><pre>
GET URL -&gt; HTML -&gt; a.href=URL -&gt; GET URL ..
</pre><p>
</p><p>
When applying this Web/REST architectural style to our integration scenario, there are
things that we can say right now with certainty will be different, but will have
corresponding elements:
</p><ul>
<li>It&#39;s about data not documents, so HTML is probably going to be replaced by XML, although perhaps XHTML+Microformats or Atom would make a good compromise;</li>
<li>We have a choice of link specs: xhtml:a.href, atom:link.rel, xml:xlink; I don&#39;t think we&#39;ll be using XLink since no-one else seems to;</li>
<li>We&#39;ll probably use machine-generated URLs perhaps containing UUIDs, GUIDs or whatever.</li>
</ul><p>
In other words, we&#39;re not going to be spinning a hypermedia Web - it&#39;s more a
&#39;hyperdata&#39; Web.
</p><p>
So, in order to emulate the document Web in our hyperdata integration Web, we&#39;ll mostly
be doing something like:
</p><pre>
GET ID-URL -&gt; XHTML -&gt; a.href=ID-URL -&gt; GET ID-URL ..
</pre><p>
</p><p>&#160;</p><p>
Oh! I&#39;ve got some 
<a href="http://docs.google.com/present/view?id=0AUwWWDrZPVcFZGZtODR6YzZfMGhiM3MyMmR0&amp;hl=en">slides</a>
of all this on Google Docs: we&#39;re up to Slide 2! Maybe right-click, open in a new window...
</p><p>&#160;</p><p>
<b>Symmetry - Slide 3</b>
</p><p>
But by far the biggest difference between the Web and an integration scenario is that
the asymmetry on the network goes away; even for a cross-enterprise integration.
</p><p>
Where the Web&#39;s browser clients and site servers have always been asymmetric - clients
being hidden away and only able to establish outbound connections - machine-to-machine
integration is fundamentally symmetric - all servers can be made visible to each other.
</p><p>
Now, in order to keep the well-studied benefits described in REST, including separation
of concerns, we should aim to maintain the client-server, layered structure in the use
of the protocol.
</p><p>
But <i>clients can be servers and vice-versa</i>!
</p><p>
So, in machine-to-machine integration scenarios, we have:
</p><ul>
<li>Two-way GETs on machine-minted URLs pointing at XHTML+Microformats or Atom content containing more links.</li>
</ul><p>
In other words:
</p><ul>
<li>A hyperdata Web both created and consumed by the applications being integrated.</li>
</ul><p>
All of the dynamic data or hyperdata items in our order processing scenario will be
distributed across the many applications being integrated. Each application serves
its part of the hyperdata Web to the others. 
</p><p>
And, of course, the hyperdata joins all these applications up: a payment resource
in the accounting application will point to an order resource in the order processing
application, etc.
</p><p>&#160;</p><p>
<b>Interactions and Application State</b>
</p><p>
Now, each application has its own set of business rules and constraints over the
hyperdata parts that it governs. 
</p><p>
So how exactly should the applications publishing those bits of the hyperdata Web
interact? How do orders interact with packing notes and stock levels, with payments and
accounts?
</p><p>
In the Web, you go to a site and jump some links. Each page brings in CSS, Javascript,
images, maybe iframes: an eager assembly of pages from links to many resources, in
contrast to the lazy, on-demand fetching of links from a user jumping them.
</p><p>
The browser at any time has a state that depends on the page and images, etc, currently
being viewed, plus the history of previous pages, bookmarks, etc.
</p><p>
Search engines in the Web, without a user driving things, are eager to traverse links
in order to do their work indexing pages. Order processing applications will probably
have more in common with search engines than with browsers.
</p><p>
REST describes this in terms of hypermedia - links - driving &#39;application state&#39;. 
</p><p>
So we next need to decide what &#39;application state&#39; is, in our Web- and REST-driven
architecture for machine-to-machine distributed systems; where the user driving
hypermedia link traversals is replaced by business rules or logic driving hyperdata link
traversals.
</p><p>
Each integrated application has its own &#39;application state&#39;, so, to follow REST, this
application state should be driven by the surrounding hyperdata of peer applications,
according to those business rules.
</p><p>&#160;</p><p>
<b>Application State is Linked Resources - Slide 4</b>
</p><p>
In fact - and this is a consequence of the symmetry of integration - <i>&#39;application
state&#39; is those very resources that the application contributes to the hyperdata Web!</i>
</p><p>
A stock tracking application&#39;s state is pretty well described by a bunch of resources
describing the stock levels. A fulfilment application&#39;s state could be inferred by
inspecting the outstanding packing notes.
</p><p>
We&#39;re not limited to the asymmetric browser-server of the Web, where the browser&#39;s
&#39;application state&#39; is never visible except when it POSTs something back.
</p><p>
It&#39;s more like a search engine, where you can publically access an &#39;application state&#39;
that is entirely driven by the hypermedia crawled by the search bot.  A search engine&#39;s
application state is rendered into the results page resources you see when you do a search.
</p><p>
So the resources of each application in the order processing integration are driven by the
surrounding, linked resources of the other applications.
</p><p>
You could rephrase REST&#39;s &#39;hypermedia as the engine of application state&#39; when applying
it to symmetric machine-to-machine integration in this neat way:
</p><blockquote class="others-content"><div><p>
Hyperdata as the Engine of Hyperdata.
</p></div></blockquote><p>
</p><p>&#160;</p><p>
<b>The Functional Observer Programming Model - Slide 5</b>
</p><p>
So now, how do we program the hyperdata-driven-hyperdata of our integrated applications?
</p><p>
How do we animate the stock tracking hyperdata chunk over here in the face of today&#39;s
packing notes in their hyperdata chunk over there?
</p><p>
That&#39;s what 
<a href="http://duncan-cragg.org/blog/post/forest-get-only-rest-integration-pattern/">FOREST</a>
is all about!  
</p><p>
The name &#39;FOREST&#39; stands for 
&#39;<a href="http://duncan-cragg.org/blog/post/forest-functional-observer-rest/">Functional Observer REST</a>&#39;.
</p><p>
The words &#39;Functional Observer&#39; describe FOREST&#39;s hyperdata-driven-hyperdata programming
model. But it&#39;s much simpler than it sounds...
</p><p>
<i>A FOREST resource in the hyperdata Web sets its next state as a Function of its
current state plus the state of those other resources Observed by it via its links.</i>
</p><p>
The best way to encode such state evolution is in rewrite rules or functions which match
a resource and its linked resources on the left-hand side, then rewrite that resource&#39;s
state on the right-hand side.
</p><p>&#160;</p><p>
<b>Not Like AtomPub, then</b>
</p><p>
So, quite a different conclusion from what is now the &#39;conventional REST&#39; of the four
verbs - GET, POST, PUT and DELETE.
</p><p>
Quite different from asymmetric, one-way application protocols as modelled by AtomPub,
in which clients aren&#39;t considered worthy to hold their own resources, but are allowed
only an inscrutable &#39;application state&#39;.
</p><p>
By focusing on GET and the freedom in integration to be symmetric, we&#39;ve arrived at a
general distributed programming model, FOREST, that allows us to express business rules
that drive an application&#39;s hyperdata in the context of another application&#39;s hyperdata.
</p><p>
Watch this blog (and <a href="http://twitter.com/duncancragg">Twitter</a>), where I&#39;ll be talking
more about the benefits of FOREST, its implementation, and, above all, offering examples of how it would work (once the code is ready enough!).
</p><p>

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/forest-get-only-rest-integration-pattern/</id>
        <title>FOREST: a GET-only REST Integration Pattern</title>
        <published>2009-10-09T17:14:00Z</published>
        
        <updated>2009-10-11T11:46:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/forest-get-only-rest-integration-pattern/" title="FOREST: a GET-only REST Integration Pattern" />
        
        <category term="architecture" />
        
        <category term="app" />
        
        <category term="dialogue" />
        
        <category term="rest" />
        
        <category term="rest-observer" />
        
        <category term="forest" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Since the day in 2006 that our
<a href="http://duncan-cragg.org/blog/post/getting-data-rest-dialogues/">dialogue</a>
took place with <i>an imaginary eBay Architect</i>, he has been promoted to <i>imaginary
Enterprise Architect</i> in an investment bank!  Convinced by the merits of REST, he took
his enthusiasm for it into his new job and embarked on architecting a trading system
using REST or ROA as an alternative to SOA.
</p><p>
Now, he hit upon a snag: he had a REST &quot;bank server&quot; generating bids on an instrument
and POSTing them into that instrument&#39;s REST &quot;market server&quot;. But then <i>he had two
copies of his bid</i>! One held by the bank server on one URI, and the other in a &quot;bid
collection&quot; held by the market server&#39;s instrument - on another URI.
</p><p>
He asked himself: &quot;Which URI is the real one? Which host &#39;owns&#39; the bid? Is the market&#39;s
copy just a cache? If so, why does it have a new URI? Why doesn&#39;t the market host know
the URI of the bank&#39;s original bid? <i>Why can&#39;t servers become clients and just GET the
data that their own data depends upon?</i>&quot; The server seemed to be dominating the 
conversation, not letting its &#39;client&#39; server have a say in things.
</p><p>
Our worried Enterprise Architect noticed that such Service-Orientation permeated REST
practice: there were &quot;REST APIs&quot; to Web sites, or &quot;Web services&quot; with a small &#39;s&#39;. Even
AtomPub had a &quot;service document&quot;!  Some patterns, like AtomPub, offered just simple
read/write data services through the full HTTP method set. Some simply used such a
read/write interface as a wrapper around more complex service functions.
</p><p>
He wondered: &quot;Where&#39;s the Web in REST integration? The Web works great without PUT and
DELETE: isn&#39;t using GET on its own RESTful enough?&quot;
</p><p>
So, remembering something I said about &quot;Symmetric REST&quot;, he contacted me again...
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Since the day in 2006 that our
<a href="http://duncan-cragg.org/blog/post/getting-data-rest-dialogues/">dialogue</a>
took place with <i>an imaginary eBay Architect</i>, he has been promoted to <i>imaginary
Enterprise Architect</i> in an investment bank!  Convinced by the merits of REST, he took
his enthusiasm for it into his new job and embarked on architecting a trading system
using REST or ROA as an alternative to SOA.
</p><p>
Now, he hit upon a snag: he had a REST &quot;bank server&quot; generating bids on an instrument
and POSTing them into that instrument&#39;s REST &quot;market server&quot;. But then <i>he had two
copies of his bid</i>! One held by the bank server on one URI, and the other in a &quot;bid
collection&quot; held by the market server&#39;s instrument - on another URI.
</p><p>
He asked himself: &quot;Which URI is the real one? Which host &#39;owns&#39; the bid? Is the market&#39;s
copy just a cache? If so, why does it have a new URI? Why doesn&#39;t the market host know
the URI of the bank&#39;s original bid? <i>Why can&#39;t servers become clients and just GET the
data that their own data depends upon?</i>&quot; The server seemed to be dominating the 
conversation, not letting its &#39;client&#39; server have a say in things.
</p><p>
Our worried Enterprise Architect noticed that such Service-Orientation permeated REST
practice: there were &quot;REST APIs&quot; to Web sites, or &quot;Web services&quot; with a small &#39;s&#39;. Even
AtomPub had a &quot;service document&quot;!  Some patterns, like AtomPub, offered just simple
read/write data services through the full HTTP method set. Some simply used such a
read/write interface as a wrapper around more complex service functions.
</p><p>
He wondered: &quot;Where&#39;s the Web in REST integration? The Web works great without PUT and
DELETE: isn&#39;t using GET on its own RESTful enough?&quot;
</p><p>
So, remembering something I said about &quot;Symmetric REST&quot;, he contacted me again...
</p></div><p>
</p><p>
<b>Enterprise Architect:</b> I see we made it into Appendix A of
<a href="http://oreilly.com/catalog/9780596529260/">the REST book</a>
by Richardson and Ruby!
</p><p>
<b>Duncan Cragg:</b> Indeed - even though I hadn&#39;t finished writing up our chat when it was
published...
</p><p>
<b>EA:</b> So why <i>did</i> it take you so long to write it up?
</p><p>
<b>DC:</b> Well, I, er, got distracted by
<a href="http://www2007.org/prog-Developers.php#saturday">Web 2.0</a> and
<a href="http://the-u-web.org/">Mobile 2.0</a>!
</p><p>
But I&#39;m back now, intending to focus more on ROA&#39;s advantages over SOA.
</p><p>
<b>EA:</b> Great! Because I wanted to talk to you about that.
</p><p>
Where I now work, we are looking at REST or ROA as an alternative to SOA. However, all the
available REST patterns still seem to see the world through Service-Oriented eyes.
</p><p>
I want to do REST like the Web does: to have different servers just publishing stuff that&#39;s
all linked up. And &quot;mashed up&quot;: to have that stuff, that data, &quot;over here&quot; depend on
that data &quot;over there&quot;: meaning that servers can be clients and vice-versa.
</p><p>
<b>DC:</b> Hyperdata that depends on someone else&#39;s hyperdata!  Maybe rewrite rules over
interlinked XHTML. 
</p><p>
I called it &quot;REST Observer&quot; back then, but
<a href="http://tech.groups.yahoo.com/group/rest-discuss/message/13266">recent events</a>
on the rest-discuss mailing list have left me very wary of using the word &#39;REST&#39; so
openly in the name of something!
</p><p>
So I decided to hide it within a different word: 
&#39;<a href="http://duncan-cragg.org/blog/post/forest-functional-observer-rest/">FOREST</a>&#39;!
</p><p>
Here is a 
<a href="http://tech.groups.yahoo.com/group/rest-discuss/message/13765">posting</a>
about FOREST that I recently made to the rest-discuss mailing list:
</p><p>&#160;</p><p>
<b>FOREST</b>
</p><p>
FOREST is a GET-only REST Integration Pattern defined simply as:
</p><p>
</p><blockquote class="others-content"><div><p>
A resource&#39;s state depends on the state of other resources that it links to.
</p></div></blockquote><p>
</p><p>
This means that resource servers must also be clients in order to see those dependencies.
</p><p>&#160;</p><p>
<b>Common Web Pattern</b>
</p><p>
FOREST is a REST Pattern derived from GET-only or polling Web use-cases, including mashups:
</p><p>
</p><ul>
<li>feed aggregators or filters</li>
<li>search index results pages</li>
<li>pages that depend on a search</li>
<li>Google&#39;s mobile versions of pages</li>
<li>sites that create summaries of other Web pages</li>
<li>sites that create feeds from Web pages</li>
<li>creating pages or feeds from REST &#39;APIs&#39; (GET only)</li>
<li>Yahoo Pipes</li>
</ul><p>
</p><p>&#160;</p><p>
<b>Going Enterprisey</b>
</p><p>
FOREST is a REST Pattern for building &quot;Enterprise Mashups&quot; in an ROA / WOA / SOA.
</p><p>
OK - those of you without Dion Hinchcliffe in your feed reader may be feeling a little
queasy at this point, but I&#39;d encourage you to read on ... Actually, I quite like the
phrase &quot;Enterprise Mashup&quot; since it lightens the gravity of that &#39;Enterprise&#39; word.
</p><p>
<a href="http://www.openmashup.org/omadocs/v1.0/emml/createMashupScript.html">Enterprise Mashup Markup Language</a>
is the nearest thing to this that I know about, but FOREST is quite different: it is
much simpler and is /only/ a REST Pattern.
</p><p>&#160;</p><p>
<b>Patterns can be implemented in frameworks...</b>
</p><p>
A FOREST implementation would inevitably be over HTTP. It would initially be just XHTML
or Atom. I imagine fetching XHTML resources within which are expected to be links to
more such documents. Any XHTML could depend on any other, and they&#39;re all interlinked.
If you depend on another resource, you must have found it directly or indirectly through
links in your body. Alternative discovery: a resource could be told that it is being
watched using an HTTP header in the GET request listing the URIs of the resources that
depend on it - then it could watch and link back.  Etag would be used for an
automatically incremented version number.
</p><p>&#160;</p><p>
<b>Rough Consensus and Working Code</b>
</p><p>
I would ideally see this work towards a formal description via &quot;rough consensus and
working code&quot;. I intend to knock up a prototype of FOREST in a Jetty servlet and post it
to GitHub; if that code works, I may get rough consensus...
</p><p>
What a FOREST XHTML/HTTP formalisation would specify: <i>Updated</i>
</p><p>
</p><ul>
<li>use of HTTP headers (Etag, Cache-Control, Content-Location, Referer*)</li>
<li>API*: doc builder, XPath body set/get*, callbacks (observed, notified*)</li>
</ul><p>
Notes (*):
</p><ul>
<li>&#39;Referer&#39; is a possible header for the URIs of dependent resources</li>
<li>the API would be language-independent, but probably Java-like</li>
<li>the XPath &#39;get&#39; would be extended to jump links from doc to doc</li>
<li>every doc jumped to gets observed</li>
<li>&#39;notified&#39; means being told when the GET returns with the observed state</li>
</ul><p>
</p><p>&#160;</p><p>
What a FOREST Java servlet and client library would implement &#39;under&#39; these specs:
</p><p>
</p><ul>
<li>a driver module loader: drivers animate resources through the API</li>
<li>a document cache - in memory and maybe saved to disk or database</li>
</ul><p>
</p><p>
Resource animation would either be by the application of business rules driving the API,
or by adapting between external state and the API.
</p><p>&#160;</p><p>
<b>Amazing</b>
</p><p>
<b>EA:</b> Wow! That&#39;s amazing! Can I help build it?
</p><p>
<b>DC:</b> Of course you can. Know any Java?
</p><p>

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/forest-functional-observer-rest/</id>
        <title>FOREST: Functional Observer REST</title>
        <published>2009-10-06T10:28:00Z</published>
        
        <updated>2009-10-06T10:28:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/forest-functional-observer-rest/" title="FOREST: Functional Observer REST" />
        
        <category term="rest-observer" />
        
        <category term="forest" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><ul>
<li>Functional Observer REST = Hyperdata Interdependency requiring Symmetric REST</li>
<li>Hyperdata Interdependency = a resource&#39;s state is a Function of its linked resource context</li>
<li>Symmetric REST = servers become clients in order to Observe the dependencies of their resources</li>
</ul><p> &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><ul>
<li>Functional Observer REST = Hyperdata Interdependency requiring Symmetric REST</li>
<li>Hyperdata Interdependency = a resource&#39;s state is a Function of its linked resource context</li>
<li>Symmetric REST = servers become clients in order to Observe the dependencies of their resources</li>
</ul><p>
</p>

            </div>
        </content>
    </entry>
    
</feed>

