Product Map
Generate, manage, orchestrate, and pipeline RSS Feeds.

RSSBus Feed Server

RSSBus Desktop

RSSBus Connectors


Developer Tools
Produce and consume data feeds from any application? For .NET, Java / J2EE, COM, C++, etc.:

 RSSTools Components



Categories
 
 
 


RSS 2.0 | Send mail to the author(s)

Friday, January 11, 2008

The API's on the web have simplified in the recent past. There are more REST-centric APIs in the public domain than ever before. Various services from Google and Amazon are a good example. Apart from being RESTful these services have a simple XML based response format. The xmlHttp operation, included in XmlOps, makes it easy to access such services and represent their results as RSS, HTML, an Excel spreadsheet, or any other output format supported by RSSBus.

Today we show an example of using xmlHttp to access the Amazon ECS service. The XmlOps connector includes this script as a demo.

<!-- Amazon Books Feed -->
<
rsb:info title="Amazon Book Search"
 
description="Use the Amazon web-services API to search for a book.">
  <
input name="query" req="true" desc="The search text." 
       
default="Harry Potter" />
</
rsb:info>
   

<!--
Create the input URL -->
<
rsb:set attr="in.url" value="http://webservices.amazon.com/onca/xml"/>
<
rsb:set attr="in.url" value="[in.url]?Service=AWSECommerceService"/>
<
rsb:set attr="in.url" value="[in.url]&SubscriptionId=0E8MHMPRK05NWG9AJ8G2"/>
<
rsb:set attr="in.url" value="[in.url]&Operation=ItemSearch"/>
<
rsb:set attr="in.url" value="[in.url]&SearchIndex=Books"/>
<
rsb:set attr="in.url" value="[in.url]&ResponseGroup=Large"/>
<
rsb:set attr="in.url" value="[in.url]&Title=[query | urlencode ]"/>
      
<!--
  Specify the item XPath. An item is pushed each time this path is

  encountered in the XML response.

-->

<
rsb:set attr="in.item" value="/ItemSearchResponse/Items/Item"/>
   
<!-- Specify the XPath of the attributes to be pushed in an item. -->
<
rsb:set attr="in.attr#" value="ASIN"/>
<
rsb:set attr="in.attr#" value="DetailPageURL"/>
<
rsb:set attr="in.attr#" value="MediumImage/URL"/>
<
rsb:set attr="in.attr#" value="ItemAttributes/Title"/>
<
rsb:set attr="in.attr#" value="ItemAttributes/Author"/>
<
rsb:set attr="in.attr#" value="ItemAttributes/NumberOfPages"/>
<
rsb:set attr="in.attr#" value="ItemAttributes/ISBN"/>
<
rsb:set attr="in.attr#" value="ItemAttributes/PublicationDate"/>
<
rsb:set attr="in.attr#" value="ItemAttributes/Publisher"/>
<
rsb:set attr="in.attr#" value="ItemAttributes/ReadingLevel"/>
<
rsb:set attr="in.attr#"
       
value="ItemAttributes/ListPrice/FormattedPrice"/>
      

<!--
Use xmlHttp to get the results  -->
<
rsb:call op="xmlHttp" in="in" out="output" >
  <
rsb:set attr="rss:link" value="[DetailPageURL]"/>
  <
rsb:set attr="rss:guid" value="[ASIN]"/>
  <
rsb:push title="[Title]">
    <
a href="[DetailPageURL]">
      <
img src="[URL]" alt="[Title]"/>
    </
a> <br/>
    Author: [Author | implode(',') ]
<br/>
    Pages: [NumberOfPages | def('Unknown')]
<br/>
    Price: [FormattedPrice | def('Unknown')]
<br/>
    ISBN: [ISBN | def('Unknown')]
<br/>
    Publication Date: [PublicationDate | def('Unknown')]
<br/>
    Publisher: [Publisher | def('Unknown')]
<br/>
    Reading Level: [ReadingLevel | def('Unknown')]
<br/>
    <
hr>
    </
rsb:push>
</
rsb:call>

In this template we use xmlHttp to call the Amazon ECS service and parse the response. We first create the request URL by appending query string parameters, and then specify the "item" and "attr#" parameters to parse the response. XmlHttp uses the Xpath notation to specify locations of interest in the response XML. The "item" xpath specifies the xpath for an item (an item is produced in the resulting feed each time this xpath is seen), and the "attr#" specify the attributes that should be present in the items of the resulting feed. The names of the attributes in the item are the same as the name of the XML elements in the response. This can be changed by using the map input parameter. The xmlHttp operation also allows you to specify the HTTP method (GET, PUT, POST and DELETE), pick a file to post, and specify HTTP headers, among other things needed to use simple XML API's.


Downloads: XmlOps

#