Invoke the REST API in the Assemble flow

In M5, Assemble flow will introduce the declarative way to invoke the REST API, the use case and design is attached.

E.g. We define the REST API for Amazon ECS Search, and put the AmazonSearch.xml under /app/assemble/services directory

<?xml version="1.0" encoding="utf-8"?>
<entry xmlns="http://www.w3.org/2005/Atom" 
      xmlns:z="http://www.projectzero.org/assemble/component">
   <title>AmanzonSearch</title>
   <link rel="http://www.projectzero.org/assemble/component/url-template" type="text/xml"
      href="http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&amp;AWSAccessKeyId={AWSAccessKeyId}&amp;Operation=ItemSearch&amp;SearchIndex={category}
      &amp;Count={max-result?}&amp;Title={title}&amp;Artist={artist?}&amp;ResponseGroup=Medium,Reviews" />
   <link rel="http://www.projectzero.org/assemble/component/transform/stylesheet" 
      type="application/atom+xml" href="/stylesheet/amazon.xsl" title="atom" />
   <link rel="http://www.projectzero.org/assemble/component/transform/stylesheet" 
      type="application/json" href="/stylesheet/amazon_json.xsl" title="json" />
   <category term="amazon"/>
   <category term="search"/>
   <category term="ecommerce"/>
   <category term="book"/>
   <category term="music"/>
   <category term="movie"/>
   <summary>Amazon Search</summary>
   <category schema="http://www.projectzero.org/assemble/component/type" term="REST API"/>
   <z:parameter name="AWSAccessKeyId" required="false" description="Access key of Amazon" config="/config/amazon/accessKeyId"/>
   <z:parameter name="title" required="true"/>
   <z:parameter name="artist" required="false" />
   <z:parameter name="category" defaultValue="Books"/>
</entry>
And we can invoke that API within Assemble flow. In the follow flow we leverage the Amazon ECS to enrich the Yahoo Top Albums feed with the customer rating from Amazon.
<process name="yahooMusic"
   xmlns:aws="http://webservices.amazon.com/AWSECommerceService/2005-10-05"
   xmlns:media="http://search.yahoo.com/mrss"
   xmlns:atom="http://www.w3.org/2005/Atom">

   <feed name="topAlbums" url="http://rss.music.yahoo.com/charts/rssTopAlbums.xml" />

   <for-each name="foreachReplace" itemName="entry">
      <control source="topAlbums" />
      <input value="${topAlbums.entry.list()}" />
      <invoke name="ratingFromAWS" service="AmazonSearch">
         <input name="category" value="Music"/>
         <input name="artist" value="${entry.'media:credit'.text()}"/>
         <input name="title" value="${entry.'media:title'.text()}" />
      </invoke>

      <assign name="updateEntryTitle">
         <control source="ratingFromAWS"
            transitionCondition="ratingFromAWS.Items.Item.size() &gt; 0" />
         <copy to="entry.title[0].textContent"
            from="${entry.title.text() + ' -- Rating ' + ratingFromAWS.Items.Item[0].CustomerReviews.AverageRating.text()}" />
      </assign>
   </for-each>

   <replyGET name="reply">
      <control source="foreachReplace" />
      <input value="${topAlbums}" />
   </replyGET>
</process>

-- yili - 23 Feb 2008

r3 - 19 Mar 2008 - 13:18:50 - yili
Syndicate this site RSS ATOM
Copyright 2007 © IBM Corporation | Privacy | Terms of Use | About this site