<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: rest code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 24 Jul 2008 15:01:40 GMT</pubDate>
    <description>DZone Snippets: rest code</description>
    <item>
      <title>REST curl helper</title>
      <link>http://snippets.dzone.com/posts/show/3521</link>
      <description>// A small bash script that wraps around curl to help more easily test RESTful sites.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/bash&lt;br /&gt;AUTH="user:password"&lt;br /&gt;BASE="http://localhost:3000"&lt;br /&gt;METHOD=$1&lt;br /&gt;DEST="$BASE$2"&lt;br /&gt;XML=$3&lt;br /&gt;&lt;br /&gt;# make sure args were passed&lt;br /&gt;if [ $# -eq 0 ]; then&lt;br /&gt;        echo "usage: ./`basename $0` HTTP-METHOD DESTINATION_URI [XML]"&lt;br /&gt;        echo "example: ./`basename $0` POST "/accounts" \"&lt;account&gt;&lt;name&gt;ed&lt;/name&gt;&lt;email&gt;ed@ed.com&lt;/email&gt;&lt;/account&gt;\""&lt;br /&gt;        exit 1&lt;br /&gt;fi&lt;br /&gt;&lt;br /&gt;# execute CURL call&lt;br /&gt;curl -H 'Accept: application/xml' -H 'Content-Type: application/xml' -w '\nHTTP STATUS: %{http_code}\nTIME: %{time_total}\n' \&lt;br /&gt;-X $METHOD \&lt;br /&gt;-d "$XML" \&lt;br /&gt;-u "$AUTH" \&lt;br /&gt;"$DEST"&lt;br /&gt;&lt;br /&gt;exit 0&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 14 Feb 2007 03:39:48 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3521</guid>
      <author>bassnode (Ed)</author>
    </item>
    <item>
      <title>Amazon REST API for newLISP</title>
      <link>http://snippets.dzone.com/posts/show/2812</link>
      <description>&lt;code&gt;&lt;br /&gt;;; (amazon-op "Operation=ItemSearch&amp;SearchIndex=Books&amp;ItemPage=1&amp;Keywords=Cloud+Atlas&amp;Respon\&lt;br /&gt;seGroup=Request,Small")&lt;br /&gt;;;&lt;br /&gt;;; (amazon-op "Operation=SimilarityLookup&amp;ItemId=1400063795,0812966929&amp;SimilarityType=Random\&lt;br /&gt;&amp;ResponseGroup=Request,Large")&lt;br /&gt;;; (amazon-op "Operation=SimilarityLookup&amp;ItemId=1400063795,061873516X,0812966929&amp;Similarity\&lt;br /&gt;Type=Random&amp;ResponseGroup=Request,Small")&lt;br /&gt;&lt;br /&gt;;;  (setq x (xml-digest (amazon-op "Operation=ItemLookup&amp;ItemId=0375507256&amp;ResponseGroup=Req\&lt;br /&gt;uest,Similarities,ListmaniaLists")))&lt;br /&gt;;; Using x get a list of listmanias for an item&lt;br /&gt;;;  (map (lambda (x) (x 1 2 2)) (1 -1 (x (chop (ref 'ListmaniaLists  x)))))&lt;br /&gt;&lt;br /&gt;;; (setq y (amazon-op "Operation=ListLookup&amp;ListType=Listmania&amp;ListId=R21LV6VJEZ794O&amp;Respons\&lt;br /&gt;eGroup=ListFull"))&lt;br /&gt;;; Using y get a list of ISBNs from a listmania&lt;br /&gt;;; (map (lambda(x) (x 4 1 2 )) (8 -1 ( (y (chop (ref 'Lists y)) ) 2))) ; gives list of ISBNs\&lt;br /&gt; from the listmania&lt;br /&gt;&lt;br /&gt;;; get a list of listmania details from a list of listmanias.&lt;br /&gt;;;  (setq z   (map (lambda (x) (xml-digest (amazon-op (append "Operation=ListLookup&amp;ListType\&lt;br /&gt;=Listmania&amp;ListId=" x "&amp;ResponseGroup=ListFull"))))  (map (lambda (x) (x 1 2 2)) (1 -1 (x (c\&lt;br /&gt;hop (ref 'ListmaniaLists  x))))))  )&lt;br /&gt;;;&lt;br /&gt;;; get a list of ISBNs from all of the listmanias for the item&lt;br /&gt;;; (setq z (flat (map (lambda(y) (map (lambda(x) (x 4 1 2 )) (8 -1 ( (y (chop (ref 'Lists y)\&lt;br /&gt;) ) 2))) ) z)))&lt;br /&gt;;;&lt;br /&gt;&lt;br /&gt;;; get item info for all the ISBNs from all listmanias related to the original item&lt;br /&gt;;; (setq w (map (lambda (x) (xml-digest (amazon-op (append "Operation=ItemLookup&amp;ItemId=" x)\&lt;br /&gt;)))  (unique z)))&lt;br /&gt;&lt;br /&gt;;; get a list of pair (title,author) from w above.&lt;br /&gt;;; (map (lambda (x) (list ((x (chop (ref 'Title x))) 1)  (if (ref 'Author x)((x (chop (ref '\&lt;br /&gt;Author x)))1) "???"))) w)&lt;br /&gt;&lt;br /&gt;(define (amazon-op params)&lt;br /&gt;  (get-url (append &lt;br /&gt;"http://webservices.amazon.com/onca/xml?Service=AWSECommerceService&amp;&amp;AWSAccessKeyId=YOUROWNKEY&amp;" params)))&lt;br /&gt;&lt;br /&gt;(define (xml-digest result)&lt;br /&gt;  (xml-type-tags nil nil nil nil)&lt;br /&gt;  (setq xresult (xml-parse result (+ 1 2 4 8 16))))&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Fri, 13 Oct 2006 10:16:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2812</guid>
      <author>frontera000 (bob bae)</author>
    </item>
    <item>
      <title>Post XML using curl</title>
      <link>http://snippets.dzone.com/posts/show/181</link>
      <description>You can use curl on the command line to do a POST to an endpoint. &lt;br /&gt;&lt;br /&gt;&lt;code&gt;echo '&lt;doc&gt;&lt;item&gt;Some content.&lt;/item&gt;&lt;/doc&gt;' | curl -X POST -H 'Content-type: text/xml' -d @- http://example.com/restapi&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This is handy for adding web services to applications that do not do web services but can do command lines--FileMaker for example.</description>
      <pubDate>Sat, 16 Apr 2005 09:42:57 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/181</guid>
      <author>beutelevision (Thomas Beutel)</author>
    </item>
  </channel>
</rss>
