<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
	xmlns:media="http://search.yahoo.com/mrss/"
>

<channel>
	<title>Software As She's Developed &#187; JSON</title>
	<atom:link href="http://softwareas.com/tag/json/feed" rel="self" type="application/rss+xml" />
	<link>http://softwareas.com</link>
	<description>Mahemoff's Podcast/Blog - Web, Programming, Usability from the Author of 'Ajax Design Patterns' (AjaxPatterns.org)</description>
	<lastBuildDate>Mon, 26 Jul 2010 16:52:27 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<!-- podcast_generator="podPress/8.8" - maintenance_release="8.8.4" -->
		<copyright>Copyright &amp;#xA9; Software As She's Developed 2010 </copyright>
		<managingEditor>michael@mahemoff.com (Software As She's Developed)</managingEditor>
		<webMaster>michael@mahemoff.com (Software As She's Developed)</webMaster>
		<category>posts</category>
		<ttl>1440</ttl>
		<itunes:keywords></itunes:keywords>
		<itunes:subtitle></itunes:subtitle>
		<itunes:summary>Mahemoff's Podcast/Blog - Web, Programming, Usability from the Author of 'Ajax Design Patterns' (AjaxPatterns.org)</itunes:summary>
		<itunes:author>Software As She's Developed</itunes:author>
		<itunes:category text="Society &amp; Culture"/>
		<itunes:owner>
			<itunes:name>Software As She's Developed</itunes:name>
			<itunes:email>michael@mahemoff.com</itunes:email>
		</itunes:owner>
		<itunes:block>No</itunes:block>
		<itunes:explicit>no</itunes:explicit>
		<itunes:image href="http://softwareas.com/wp-content/plugins/podpress/images/powered_by_podpress_large.jpg" />
		<image>
			<url>http://softwareas.com/wp-content/plugins/podpress/images/powered_by_podpress.jpg</url>
			<title>Software As She's Developed</title>
			<link>http://softwareas.com</link>
			<width>144</width>
			<height>144</height>
		</image>
		<item>
		<title>Rails JSON, JSON Rails</title>
		<link>http://softwareas.com/rails-json-json-rails</link>
		<comments>http://softwareas.com/rails-json-json-rails#comments</comments>
		<pubDate>Fri, 13 Jul 2007 18:56:29 +0000</pubDate>
		<dc:creator>mahemoff</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[SoftwareDev]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[AjaxPatterns]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.softwareas.com/rails-json-json-rails</guid>
		<description><![CDATA[


&#60;

p style="clear:both; margin-top: 2em; ">
Man, JSON has come out of nowhere! I first came across it amid the Javascript hype in early '05, now it's everywhere. Not only in your Ajax apps, but in the On-Demand Javascript APIs of the world.

Sharing an ethic of simplicity with Rails, it's not surprising these technologies have come closely [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://picupper.com/2007/07/13/json.jpg" width="130" height="130" style="float: left"; />
<img src="http://picupper.com/2007/07/13/rails.png.jpg" width="130" height="130"  style="float:left; padding-left: 30px;"/></p>

<p>&lt;</p>

<p>p style="clear:both; margin-top: 2em; ">
Man, <a href="http://ajaxpatterns.org/JSON_Message">JSON</a> has come out of nowhere! I first came across it amid the Javascript hype in early '05, now it's everywhere. Not only in your Ajax apps, but in the <a href="http://ajaxpatterns.org/On-Demand_Javascript">On-Demand Javascript</a> APIs of the world.</p>

<p>Sharing an ethic of simplicity with Rails, it's not surprising these technologies have come closely together, with JSON support now baked into the Rails core. (They would have been even closer together, if only anyone had noticed <a href="http://redhanded.hobix.com/inspect/yamlIsJson.html">JSON==YAML</a> early on and merged the two completely.) And yet, the current implementation misses a couple of tricks.</p>

<ul>
<li><strong>Use of "attributes".</strong> According to Rails, a JSON object generally has just a single key, "attributes". Instead of the simple { :name=>"Pac-Man", :creator=>"Namco" }, we get (and have to give) { :attributes => { :name=>"Pac-Man", :creator=>"Namco" }}. That's not DRY. Not that it matters, but the reason for this is because ActiveRecords internally store persistable data fields in a hashmap called "attributes". The JSON serialization is therefore faithful to Rails' internal implementation, while being unfaithful to intuition. Maybe you could argue for "attributes" on the basis that you might one day have a transient attribute with the same name as a persistent attribute, in which case you'd get a clash. But Convention Over Configuration rules this argument out; you can always override JSON serialization behavior in boundary situations.
</li><li><strong>Child attributes</strong> This is probably an issue with XML as well. Basically, there is no attention paid to child attributes, i.e. JSON/XML serialization of a HABTM or has_many relationship. You want something like { :name=>"Pac-Man", :creator=>"Namco", :high_scores=>[{ :player_id=>1, :score=>99999 }, {:player_id=>2, :score=>88888 }] }, but all you get is the top-level attributes :name and :creator.
</li></ul>

<p>What to do?</p>

<p>First, I just discovered this extremely helpful library - <a href="http://blog.codefront.net/2007/07/11/better-json-output-from-rails-with-the-jsonifier-plugin/">Jsonifier</a>, which also ships as a Rails plugin. It deals with both of the above problems. There's no "attributes" chaff and it deals with associated records, even going recursive and letting you navigate from end of a many-to-many into the other. (In my example, you could show the names and ages of Pac-Man high scorers.) You also get to whitelist or blacklist attributes matches Rails' associations syntax, i.e. <img src='http://softwareas.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> nly, :except. Highly recommended, check it out.</p>

<p>Jsonifier, however, is pure to&#95;json - it doesn't (yet) handle deserialization. <a href="http://www.ruby-forum.com/topic/114361">To my knowledge</a>, there's no Rails library that persists both parent and children in one go. There are lots of forum posts about handling multiple checkboxes and the like, and the answer usually involves overriding "children=" or "child_ids=". I want to do this automatically!</p>

<p>I've been working out how to extend ActiveRecord to persist automatigically. I have the following very rough code working in basic situations, although it would need to do some more validation to work in production, among other things. It works on data structures such as the recurisve one above. You must first use a before_filter to convert the incoming JSON string into a Rails structure.</p>

<div class="igBar"><span id="lruby-2"><a href="#" onclick="javascript:showPlainTxt('ruby-2'); return false;">PLAIN TEXT</a></span></div>

<div class="syntax_hilite"><span class="langName">RUBY:</span><br /><div id="ruby-2">
<div class="ruby"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> &lt;&lt;ActiveRecord::Base</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> recursive_create<span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; transaction <span style="color:#9966CC; font-weight:bold;">do</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; collections_by_children = pluck_hash_collections_by_children params</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; new_model = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; populate_children new_model, collections_by_children</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; new_model</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> pluck_hash_collections_by_children<span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; hash_collections_by_children = Hash.<span style="color:#9900CC;">new</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; params.<span style="color:#9900CC;">each_pair</span> <span style="color:#006600; font-weight:bold;">&#123;</span> |name, value|</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> value.<span style="color:#9966CC; font-weight:bold;">class</span>==<span style="color:#CC0066; font-weight:bold;">Array</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; hash_collections_by_children<span style="color:#006600; font-weight:bold;">&#91;</span>name<span style="color:#006600; font-weight:bold;">&#93;</span> = value</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; params.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span>name<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; hash_collections_by_children</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> populate_children<span style="color:#006600; font-weight:bold;">&#40;</span>new_model, hash_collections_by_children<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; hash_collections_by_children.<span style="color:#9900CC;">each_pair</span> <span style="color:#006600; font-weight:bold;">&#123;</span> |children_name, hash_collection|</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; new_model.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"#{children_name}"</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">destroy_all</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; child_class_name = children_name.<span style="color:#9900CC;">singularize</span>.<span style="color:#9900CC;">camelize</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; child_class = Object.<span style="color:#9900CC;">const_get</span><span style="color:#006600; font-weight:bold;">&#40;</span>child_class_name<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; hash_collection.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> |child_hash|</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; child = child_class.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span>child_hash<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; new_model.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">"#{children_name}"</span><span style="color:#006600; font-weight:bold;">&#41;</span> &lt;&lt;child</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">module</span> ActiveRecord</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">class</span> Base</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> recursive_update_attributes<span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; transaction <span style="color:#9966CC; font-weight:bold;">do</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; collections_by_children = <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">pluck_hash_collections_by_children</span> params</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">update_attributes</span><span style="color:#006600; font-weight:bold;">&#40;</span>params<span style="color:#006600; font-weight:bold;">&#41;</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">populate_children</span> <span style="color:#0000FF; font-weight:bold;">self</span>, collections_by_children</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; save</div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div></li>
<li style="font-weight: bold;color:#26536A;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div></li></ol></div>
</div></div>

<p><br /></p>
]]></content:encoded>
			<wfw:commentRss>http://softwareas.com/rails-json-json-rails/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ajax Programming Patterns &#8211; Podcast 1 of 4: Web Service Patterns</title>
		<link>http://softwareas.com/ajax-programming-podcast-1-web-services</link>
		<comments>http://softwareas.com/ajax-programming-podcast-1-web-services#comments</comments>
		<pubDate>Fri, 31 Mar 2006 18:30:57 +0000</pubDate>
		<dc:creator>mahemoff</dc:creator>
				<category><![CDATA[Links]]></category>
		<category><![CDATA[Podcast]]></category>
		<category><![CDATA[SoftwareDev]]></category>
		<category><![CDATA[AjaxPatterns]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RPC]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.softwareas.com/ajax-programming-podcast-1-web-services</guid>
		<description><![CDATA[Whereupon a new podcast series begins ...

As promised, a new series of Ajax pattern podcasts. This is the first of four podcasts on the Ajax programming patterns.

In this 73 minute podcast, we look at the seven patterns of web services as they relate to Ajax clients.




 RPC Service Expose web services as Remote Procedural Calls [...]]]></description>
			<content:encoded><![CDATA[<p>Whereupon a new podcast series begins ...</p>

<p><a href="http://softwareas.com/ajax-basics-podcast-3">As promised</a>, a new series of Ajax pattern podcasts. This is the first of four podcasts on the <a href="http://ajaxpatterns.org">Ajax programming patterns</a>.</p>

<p>In this 73 minute podcast, we look at the seven patterns of web services as they relate to Ajax clients.</p>

<p><a href="http://softwareas.com/podcast/SASDAjaxProgrammingPatterns1of4-WebServices.mp3"
title="Click to download the Podcast and play it on your computer."
style="text-decoration: none;"><img src="/images/aquapodcastfileicon.gif"
border="0" alt="Click to download the Podcast. You can also subscribe to the
feed if you want future podcasts automatically downloaded - check out the
podcast FAQ at http://podca.st." border="0"/></a></p>

<ul>
<li> <span class="full"><a href="http://ajaxpatterns.org/RPC_Service" title="RPC Service">RPC Service</a> Expose web services as Remote Procedural Calls (RPCs). (Note: In the book and wiki, REST appears before RPC.) (6:55)</span></li>
<li> <span class="full"><a href="http://ajaxpatterns.org/RESTful_Service" title="RESTful Service">RESTful Service</a> Expose web services according to RESTful principles. (13:25 )</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/HTML_Response" title="HTML Response">HTML Response</a> Have the server generate HTML snippets to be displayed in the browser. (44:45)</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Semantic_Response" title="Semantic Response">Semantic Response</a> Have the server respond with abstract, semantic, data. (49:00)</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Plain-Text_Message" title="Plain-Text Message">Plain-Text Message</a> Pass simple messages between server and browser in plain-text format. (56:05)</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/XML_Message" title="XML Message">XML Message</a> Pass messages between server and browser in XML format. (57:20)</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/JSON_Message" title="JSON Message">JSON Message</a>  Pass messages between server and browser in Javascript Object Notation (JSON) format. (59:55)</span>
</li></ul>

<p>Thanks for your feedback since last time. Good, bad, or ugly, it's all welcome - in the comments for this podcast or michael@mahemoff.com.<!--d06b114ae65af257cf296ee565e3ba88--></p>
]]></content:encoded>
			<wfw:commentRss>http://softwareas.com/ajax-programming-podcast-1-web-services/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
<enclosure url="http://softwareas.com/podcast/SASDAjaxProgrammingPatterns1of4-WebServices.mp3" length="35402176" type="audio/mpeg" />
		</item>
		<item>
		<title>New Ajax Demos</title>
		<link>http://softwareas.com/new-ajax-demos</link>
		<comments>http://softwareas.com/new-ajax-demos#comments</comments>
		<pubDate>Fri, 16 Sep 2005 19:37:26 +0000</pubDate>
		<dc:creator>mahemoff</dc:creator>
				<category><![CDATA[HumansAndTech]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[SoftwareDev]]></category>
		<category><![CDATA[AjaxPatterns]]></category>
		<category><![CDATA[Demos]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RPC]]></category>
		<category><![CDATA[Web2.0]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.softwareas.com/new-ajax-demos</guid>
		<description><![CDATA[Further to the previous post on new Ajax programming patterns, it's also worth noting there's a new bunch of corresponding online Ajax demos too. Being programming patterns, they tend to be "pure refactorings" rather than enhancements, thus the user experience is mostly the same - you have to look under the covers to see what's [...]]]></description>
			<content:encoded><![CDATA[<p>Further to the <a href="http://www.softwareas.com/18-new-ajax-programming-patterns">previous post on new Ajax programming patterns</a>, it's also worth noting there's a new bunch of corresponding <a href="http://ajaxify.com/run">online Ajax demos</a> too. Being programming patterns, they tend to be "pure refactorings" rather than enhancements, thus the user experience is mostly the same - you have to look under the covers to see what's changed. The demos are mentioned in individual patterns, but here's a sampling:</p>

<ul>
<li>The wiki has a bunch of <a href="http://www.ajaxify.com/run/wiki/timeout/">timeout-related refactorings</a>. These refactorings <em>are</em> user-visible. (They're not actually part of the programming patterns, but they were recently added.)</li>
<li>2 other wiki refactorings involve <a href="http://www.ajaxify.com/run/wiki/separateJS/">On-Demand Javascript</a> . (No UI change.)</li>
<li>A <a href="http://www.ajaxify.com/run/json/">JSON playground</a>.</li>
<li>The <a href="http://www.ajaxify.com/run/portal/drilldown/">Portal Drilldown Demo</a> has been refactored to render with XSLT and browser templating tools. (No UI change.)</li>
<li>A couple of refactorings added to demonstrate <a href="http://www.ajaxify.com/run/shop/rest/">REST</a> (broken right now, probably due to a PHP config issue) and <a href="http://www.ajaxify.com/run/shop/rpc/">RPC</a> on the Ajax Shop demo. (No UI change.)</li>
</ul>

<p>As with all the demos, they're tested on FF and IE6, please let me know if anything breaks.</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareas.com/new-ajax-demos/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>18 New Ajax Programming Patterns</title>
		<link>http://softwareas.com/18-new-ajax-programming-patterns</link>
		<comments>http://softwareas.com/18-new-ajax-programming-patterns#comments</comments>
		<pubDate>Fri, 16 Sep 2005 19:09:05 +0000</pubDate>
		<dc:creator>mahemoff</dc:creator>
				<category><![CDATA[HumansAndTech]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[SoftwareDev]]></category>
		<category><![CDATA[AjaxPatterns]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RPC]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[Web2.0]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.softwareas.com/18-new-ajax-programming-patterns</guid>
		<description><![CDATA[I've uploaded full text for 18 new Ajax patterns, completing a first-cut draft for all Programming Patterns content, which will be one part of the book. This section bridges the gap between the very basics of Ajax - XMLHttpRequest, DOM, etc - and the high-level stuff like widgets and visual effects. For instance, how do [...]]]></description>
			<content:encoded><![CDATA[<p><strong>I've uploaded full text for <a href="http://ajaxpatterns.org">18 new Ajax patterns</a>, completing a first-cut draft for all Programming Patterns content, which will be one part of the book. This section bridges the gap between the very basics of Ajax - XMLHttpRequest, DOM, etc - and the high-level stuff like widgets and visual effects.</strong> For instance, how do you do design the services accessed by XMLHttpRequest? Or how do you deal with a lots of Javascript? The focus here is on traditional tech concerns such as maintainability and understandability; and less about usability.</p>

<p>Breaking it down:</p>

<ul>
<li><p><strong>Web Services</strong> patterns are about overall browser-server architecture - what kinds of services and what kinds of messages? It's relevant to the conversation of <a href="http://blogs.codehaus.org/people/tirsen/archives/001154_designs_for_remote_calls_in_ajax.html">Jon Tiersen</a> and others about what sort of responses are possible - XML, JS, HTML, JSON. It's also relevant to another recent conversation, on [http://www.theserverside.com/news/thread.tss?thread_id=35979 Ajax and webservices], as it covers REST and RPC.</p></li>
<li><p><strong>Browser-Server Dialogue</strong> covers a mixed bag of patterns about XMLHttpRequest handling and what you can do with it, such as loading JS on demand.</p></li>
<li><p><strong>DOM Population</strong> is about transforming incoming XML into DOM content, e.g. XSLT.</p></li>
<li><p><strong>Performance Optimisation</strong> covers a variety of performance patterns such as caching and pre-fetching.</p></li>
<li><p><strong>Breakout</strong> (can you think of a better name) is about going beyond standard Ajax constraints, namely using a server-side mediator to access external domains and introducing a plugin to go where no Ajax app is allowed to go.</p></li>
<li><p><strong>Code Generation and Reuse</strong> is strongly  related to some of <a href="http://ajaxpatterns.org/Ajax_Frameworks">the emerging frameworks</a> like Echo2 and SAJAX.</p></li>
</ul>

<p>This is all <strong>early</strong> days, so any feedback on the structure, names, or content will be taken into account and acknowledged too (really!). OK, here's the lot ...</p>

<div class="editsection" style="float:right;margin-left:5px;"></div>

<p><a name="Programming_Patterns_.2840.29"></a></p>

<h1> Programming Patterns</h1>

<div class="editsection" style="float:right;margin-left:5px;"></div>

<p><a name="Web_Services"></a></p>

<h2> Web Services </h2>

<ul><li> <span class="full"><a href="http://ajaxpatterns.org/RESTful_Service" title="RESTful Service">RESTful Service</a> Expose web services according to RESTful principles.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/RPC_Service" title="RPC Service">RPC Service</a> Expose web services as Remote Procedural Calls (RPCs).</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/HTML_Response" title="HTML Response">HTML Response</a> Have the server generate HTML snippets to be displayed in the browser.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Semantic_Response" title="Semantic Response">Semantic Response</a> Have the server respond with abstract, semantic, data.</span>

</li><li> <span class="full"><a href="http://ajaxpatterns.org/Plain-Text_Message" title="Plain-Text Message">Plain-Text Message</a> Pass simple messages between server and browser in plain-text format.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/XML_Message" title="XML Message">XML Message</a> Pass messages between server and browser in XML format.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/JSON_Message" title="JSON Message">JSON Message</a>  Pass messages between server and browser in Javascript Object Notation (JSON) format.</span>
</li></ul>

<div class="editsection" style="float:right;margin-left:5px;"></div>

<p><a name="Browser-Server_Dialogue"></a></p>

<h2> Browser-Server Dialogue  </h2>

<ul><li> <span class="full"><a href="http://ajaxpatterns.org/Call_Tracking" title="Call Tracking">Call Tracking</a> Accommodate busy user behaviour by allocating a new XMLHtpRequest object for each request. See <a href="http://smokey.rhs.com/web/blog/poweroftheschwartz.nsf/d6plinks/RSCZ-6CEQAR" class='external' title="http://smokey.rhs.com/web/blog/poweroftheschwartz.nsf/d6plinks/RSCZ-6CEQAR" rel="nofollow">Richard Schwartz's blog entry</a></span><span class='urlexpansion'>&nbsp;(<i>http://smokey.rhs.com/web/blog/poweroftheschwartz.nsf/d6plinks/RSCZ-6CEQAR</i>)</span>.<b>Note:</b> Pending some rewrite to take into account request-locking etc.
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Distributed_Events" title="Distributed Events">Distributed Events</a> Keep objects synchronised with an event mechanism.</span>

</li><li> <span class="full"><a href="http://ajaxpatterns.org/On-Demand_Javascript" title="On-Demand Javascript">On-Demand Javascript</a> Download Javascript as and when required, instead of downloading it all on page load.</span>
</li></ul>

<div class="editsection" style="float:right;margin-left:5px;"></div>

<p><a name="DOM_Population"></a></p>

<h2> DOM Population </h2>

<ul><li> <span class="full"><a href="http://ajaxpatterns.org/XML_Data_Island" title="XML Data Island">XML Data Island</a> Retain XML responses as "XML Data Islands", nodes within the HTML DOM.</span>

</li><li> <span class="full"><a href="http://ajaxpatterns.org/Browser-Side_XSLT" title="Browser-Side XSLT">Browser-Side XSLT</a> Apply XSLT to convert </span><span class="full"><a href="http://ajaxpatterns.org/XML_Message" title="XML Message">XML Messages</a> into XHTML.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Browser-Side_Templating" title="Browser-Side Templating">Browser-Side Templating</a> Produce browser-side templates and call on a suitable browser-side framework to render them as HTML.</span>
</li></ul>

<div class="editsection" style="float:right;margin-left:5px;"></div>

<p><a name="Performance_Optimisation"></a></p>

<h2> Performance Optimisation </h2>

<ul><li> <span class="full"><a href="http://ajaxpatterns.org/Fat_Client" title="Fat Client">Fat Client</a> Create a rich, browser-based, client by performing remote calls only when there is no way to achieve the same effect in the browser.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Browser-Side_Cache" title="Browser-Side Cache">Browser-Side Cache</a> Maintain a local cache of information.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Guesstimate" title="Guesstimate">Guesstimate</a> Instead of grabbing real data from the server, make a guesstimate that's good enough for most user's needs.
</span></li><li> <span class="full"><a href="http://ajaxpatterns.org/Submission_Throttling" title="Submission Throttling">Submission Throttling</a> Instead of submitting upon each Javascript event, retain the data in a local buffer and upload it periodically.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Explicit_Submission" title="Explicit Submission">Explicit Submission</a> Instead of submitting upon each Javascript event, require the user to explicitly request it, e.g. submit upon clicking a button.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Multi-Stage_Download" title="Multi-Stage Download">Multi-Stage Download</a> Quickly download the page structure with a standard request, then populate it with further requests.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Predictive_Fetch" title="Predictive Fetch">Predictive Fetch</a> Anticipate likely user actions and pre-load the required data.</span>

</li></ul>

<div class="editsection" style="float:right;margin-left:5px;"></div>

<p><a name="Breakout"></a></p>

<h2> Breakout </h2>

<ul><li> <span class="full"><a href="http://ajaxpatterns.org/Cross-Domain_Mediator" title="Cross-Domain Mediator">Cross-Domain Mediator</a> Allow the browser to communicate with other domains by server-based mediation.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Richer_Plugin" title="Richer Plugin">Richer Plugin</a> Make your application "more Ajax than Ajax" with a Richer Plugin.</span>

</li></ul>

<div class="editsection" style="float:right;margin-left:5px;"></div>

<p><a name="Code_Generation_and_Reuse"></a></p>

<h2> Code Generation and Reuse </h2>

<ul><li> <span class="full"><a href="http://ajaxpatterns.org/Ajax_Stub" title="Ajax Stub">Ajax Stub</a> Use an "Ajax Stub" framework which allows browser scripts to directly invoke server-side operations, without having to worry about the details of XMLHttpRequest and HTTP transfer.</span>
</li><li> <span class="full"><a href="http://ajaxpatterns.org/Server-Side_Code_Generation" title="Server-Side Code Generation">Server-Side Code Generation</a> Automatically generate HTML and Javascript from server-side code.</span>

</li><li> <span class="full"><a href="http://ajaxpatterns.org/Cross-Browser_Component" title="Cross-Browser Component">Cross-Browser Component</a> Create cross-browser components, allowing programmers to reuse them without regard for browser compatibility.</span>
</li></ul>

<hr />

<p><strong>Aside</strong> I was interviewed yesterday for a Japanese magazine about how I'm using the wiki. So maybe some people will be interested to know that I always write the patterns offline because I am more creative in Vim and also to avoid textarea hell. (So much for Writely, will anyone create Vimly, there's gotta be more money it than cloning MS-Word online <img src='http://softwareas.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> ). I also use the Mozex or ViewSourceWith extensions to make partial edits using Vim.</p>

<p>This time, I decided not to upload once or twice at a time; but instead all 18 at once.
There's serious overhead of introducing each new pattern to the wiki (from Vim, the sequence is: 2mins spell-check, 5-10mins markup massaging, 2 mins fixing the link and description on the homepage; sometimes exacerbated by server lag.) Uploading all at once at least allowed me to focus fully on the task and also made some aspects more efficient, particularly updating the homepage.)</p>
]]></content:encoded>
			<wfw:commentRss>http://softwareas.com/18-new-ajax-programming-patterns/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
