]> gitweb.factorcode.org Git - factor.git/blob - basis/xml-rpc/example.factor
Create basis vocab root
[factor.git] / basis / xml-rpc / example.factor
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 ;
5
6 : functions
7     H{ { "add" [ + ] }
8        { "subtract" [ - ] }
9        { "multiply" [ * ] }
10        { "divide" [ / ] } } ;
11
12 : apply-function ( name args -- {number} )
13     >r functions hash r> first2 rot call 1array ;
14
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 ;
18
19 : respond-rpc-arith ( -- )
20     "raw-response" get
21     string>xml problem>solution xml>string
22     put-http-response ;
23
24 : test-rpc-arith
25     "add" { 1 2 } <rpc-method> send-rpc
26     "http://localhost:8080/responder/rpc/"
27     http-post ;