A Lazy Sequence

ANN: Necessary-Evil

Announcing necessary evil; a library for XML-RPC client and server in Clojure. necessary-evil is built on top of the ring and clj-http libraries and should be trivial for anyone to slot into an existing web site.

The code is available on github

Here is a straightforward hello world server:

(require '[necessary-evil.core :as xml-rpc])
(use 'ring.adapter.jetty)

(def handler (xml-rpc/end-point 
    {:hello (fn hello 
        ([] (hello "World"))
        ([name] (str "Hello, " name "!")))}))

(run-jetty handler {:port 3000})

We can test this out with the following (in a seperate repl):

(require '[necessary-evil.core :as xml-rpc])

(prn (xml-rpc/call "http://localhost:3000" :hello)) 
; => "Hello, World!"

(prn (xml-rpc/call "http://localhost:3000" :hello "Necessary Evil")) 
; => "Hello, Necessary Evil!"

or from a Python shell:

>>> import xmlrpclib
>>> s = xmlrpclib.ServerProxy("http://localhost:3000")
>>> s.hello()
'Hello, World!'
>>> s.hello("python")
'Hello, python!'