UserPreferences

SampleXmlrpc


Sample Package

AnswerMe: XML-RPC <dateTime.iso8601> elements do not support timezones.

AnswerMe: missing a representation for ent:topic.

AnswerMe: how will this work with any SyntaxExtensionMechanism

<?xml version=\"1.0\" encoding=\"UTF-8\"?>
  < methodResponse>
    <params>
      <param>
          <value>
            <struct>
              <member>
                <name>title</name>
                  <value>
                    <string>My First Entry</string>
                  </value>
              </member>
              <member>
                <name>summary</name>
                  <value>
                    <string>A very boring entry; just learning how to blog here...</string>
                  </value>
              </member>
              <member>
                <name>author</name>
                  <value>
                    <struct>
                      <member>
                        <name>name</name>
                        <value>
                          <string>Bob B. Bobbington</string>
                        </value>
                      </member>
                       <member>
                        <name>homepage</name>
                        <value>
                          <string>http://bob.name/</string>
                        </value>
                      </member>
                      <member>
                        <name>weblog</name>
                        <value>
                          <string>http://bob.blog/</string>
                        </value>
                      </member>
                   </struct>
                  </value>
              </member>
              <member>
                <name>contributor</name>
                  <value>
                    <struct>
                      <member>
                        <name>name</name>
                        <value>
                          <string>Yo-Yo Dyne</string>
                        </value>
                      </member>
                       <member>
                        <name>homepage</name>
                        <value>
                          <string>http://yoyo.dyne.name/</string>
                        </value>
                      </member>
                      <member>
                        <name>weblog</name>
                        <value>
                          <string>http://blog.yoyo.dyne.name/</string>
                        </value>
                      </member>
                   </struct>
                  </value>
              </member>
              <member>
                <name>link</name>
                  <value>
                    <string>http://bob.blog/28</string>
                  </value>
              </member>
              <member>
                <name>id</name>
                  <value>
                    <string>http://bob.blog/28</string>
                  </value>
              </member>
              <member>
                <name>created</name>
                  <value>
                    <dateTime.iso8601>2003-02-05T12:29:29Z</dateTime.iso8601>
                  </value>
              </member>
              <member>
                <name>issued</name>
                  <value>
                    <dateTime.iso8601>2003-02-05T08:29:29-04:00</dateTime.iso8601>
                  </value>
              </member>
              <member>
                <name>modified</name>
                  <value>
                    <dateTime.iso8601>2003-02-05T12:29:29Z</dateTime.iso8601>
                  </value>
              </member>
              <member>
                <name>content</name>
                  <value>
                    <string>Hello, &lt;em&gt;weblog&lt;/em&gt; world! 2 &lt; 4!</string>
                  </value>
              </member>
            </struct>
          </value>
      </param>
    </params>
  </methodResponse>

Sample Call Using Toolkit

Cold Fusion

[RogerBenningfield, RefactorOk] In response to Sam's request in XmlRpcDiscussion, here's some ColdFusion code that returns an Echo feed to the client. Please note that it will generate a package that is slightly different than the above example. I've made every element a struct, while the example uses simple types for elements such as <title>. My way seems more consistent, but the example is pretty much in line with existing APIs, so maybe I'm nuts.

AnswerMe: the following does not put dates in an dateTime.iso8601.

AnswerMe: the 'ent' prefix in 'ent:topic' is associated with a namespace, where is that defined?

<cfscript>
 myResponse = ArrayNew(1);
 myResponse[1] = StructNew();
 myResponse[1].title.value = "My First Entry";
 myResponse[1].summary.value = "A very boring entry; just learning how to blog here...";
 myResponse[1].author.name.value = "Bob B. Bobbington";
 myResponse[1].author.homepage.value = "http://bob.name/";
 myResponse[1].author.weblog.value = "http://blog.yoyo.dyne.name/";
 myResponse[1].contributor = ArrayNew(1);
 myResponse[1].contributor[1] = StructNew();
 myResponse[1].contributor[1].name.value = "Yo-Yo Dyne";
 myResponse[1].contributor[1].homepage.value = "http://yoyo.dyne.name/";
 myResponse[1].contributor[1].name.value = "http://blog.yoyo.dyne.name/";
 myResponse[1].link.value = "http://bob.blog/28";
 myResponse[1].id.value = "http://bob.blog/28";
 myResponse[1].created.value = "20030205T12:29:29";
 myResponse[1].issued.value = "20030205T08:29:29";
 myResponse[1].modified.value = "20030205T12:29:29";
 myResponse[1].content = ArrayNew(1);
 myResponse[1].content[1] = StructNew();
 myResponse[1].content[1].type = "application/xhtml+xml";
 myResponse[1].content[1]["xml:lang"] = "en-us";
 myResponse[1].content[1].value = "<p xmlns=""..."">Hello, <em>weblog</em> world! 2 &lt; 4!</p>";
 myResponse[1].content[2] = StructNew();
 myResponse[1].content[2].type = "text/html";
 myResponse[1].content[2]["xml:lang"] = "en-us";
 myResponse[1].content[2].value = "<p>Hello, <em>weblog</em> world! 2 &lt; 4!</p>";
 myResponse[1].content[3] = StructNew();
 myResponse[1].content[3].type = "text/plain";
 myResponse[1].content[3]["xml:lang"] = "en-us";
 myResponse[1].content[3].mode = "escaped";
 myResponse[1].content[3].value = "Hello, _weblog_ world! 2 < 4!";
 myResponse[1].content[4] = StructNew();
 myResponse[1].content[4].type = "image/png";
 myResponse[1].content[4]["xml:lang"] = "en-us";
 myResponse[1].content[4].src = "http://bob.blog/helloworld.png";
 myResponse[1]["ent:topic"] = StructNew();
 myResponse[1]["ent:topic"].id = "introductory";
 myResponse[1]["ent:topic"].value = "Hello";
 myResponse[2].namespaces = StructNew();
 myResponse[2].namespaces.ent = "http://www.purl.org/NET/ENT/1.0/";
</cfscript>
<cfinvoke component="xmlrpc"  
        method="CFML2XMLRPC" 
        returnvariable="myResponsePackage" 
        data="#myResponse#"
        lowercasenames="true"
        type="response">

Python

[GeorgBauer, RefactorOk] This is an example in python using the XML-RPC API. A SOAP call would look mostly the same. I still use the cleartext password stuff as most other XML-RPC APIs use, but it's not really necessary, you can quite easily use basic authentication or other stuff from your webserver. Or implement a challenge-response method based on XML-RPC calls (that's what I used in other places). The nice side of this for Python: I can work with internal data structures. I took some freedom to translate the XML into meaningfull structures, it's not necessarily this format, it could be different. For example I introduced a "value" element for those cases where I need to transport attributed tags and used the tags directly where there are nested tags. This is not the best way to do it, there are several problems with it (for example the conversion back to XML of unknown structure elements - you don't know wether the id and value of ent_topic are subelements or attributes, if you don't know about ent_topic's structure itself), it's just a sample to show how it _could_ look like.

[MarkPilgrim] I've taken this mapping, applied it to [WWW]Section 4.2 of Echo Api, and mocked up [WWW]an apples-to-apples comparison between REST and XML-RPC of posting a new entry.

dateTime.iso8601 does not support timezones.

import xmlrpclib

srv = xmlrpclib.Server('http://some.connector.de/RPC2')

item = {
   '_xmlns_ent': 'http://www.purl.org/NET/ENT/1.0/',
   'title': 'some title',
   'summary': 'the summary, quite boring stuff',
   'author': {
      'name': 'Georg Bauer',
      'homepage': 'http://pyds.muensterland.org/',
      'weblog': 'http://pyds.muensterland.org/weblog/'
   }
   'contributor': [
      {
         'name': 'Phillip Pearson',
         'homepage': 'http://pycs.net/',
         'weblog': 'http://pycs.net/post/'
      }
   ],
   'link': 'http://pyds.muensterland.org/weblog/2003/07/01.html#P999',
   'id': 'P999',
   'created': xmlrpclib.DateTime('2003-05-06T08:29:29-04:00'),
   'issued': xmlrpclib.DateTime('2003-05-06T10:00:00Z'),
   'modified': xmlrpclib.DateTime('2003-06-01T12:00:00Z'),
   'content': [
      {
          '_xml_lang': 'en-us',
          '_type': 'text/html',
          'value_': '<p>This is a paragraph</p>'
      },
      {
          '_xml_lang': 'en-us',
          '_type': 'text/plain',
          'value_': 'This is a paragraph'
      }
   ]
   'ent_topic': {
      '_id': 'introductory',
      'value_': 'some value'
   }
}

srv.newPost(user, password, item)


CategoryApi, CategorySyntax