Merge branch 'master' of git://factorcode.org/git/factor
[factor/jcg.git] / basis / xml-rpc / example.factor
blobe2be36c4504c0d18f05300f18088067362373309
1 IN: rpc-example
2 REQUIRES: contrib/http-client contrib/calendar ;
3 USING: kernel hashtables xml-rpc xml calendar sequences
4     arrays math httpd io http-client namespaces ;
6 : functions
7     H{ { "add" [ + ] }
8        { "subtract" [ - ] }
9        { "multiply" [ * ] }
10        { "divide" [ / ] } } ;
12 : apply-function ( name args -- {number} )
13     [ functions hash ] dip first2 rot call 1array ;
15 : problem>solution ( xml-doc -- xml-doc )
16     receive-rpc dup rpc-method-name swap rpc-method-params
17     apply-function <rpc-response> send-rpc ;
19 : respond-rpc-arith ( -- )
20     "raw-response" get
21     string>xml problem>solution xml>string
22     put-http-response ;
24 : test-rpc-arith
25     "add" { 1 2 } <rpc-method> send-rpc
26     "http://localhost:8080/responder/rpc/"
27     http-post ;