Changeset 15253 in project


Ignore:
Timestamp:
07/25/09 16:35:48 (10 years ago)
Author:
sjamaan
Message:

Document new server stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/xml-rpc

    r15233 r15253  
    7777==== Server
    7878
    79 The server is still under construction. The building blocks for
    80 creating your own server are in place already:
    81 
    8279Usage:
    8380  (require-extension xml-rpc-server)
     81
     82<procedure>(make-xml-rpc-request-handler procedures)</procedure>
     83
     84This creates a procedure which accepts two arguments; an [intarweb]
     85request object and a response object.  It will read an XML-RPC request
     86from the request-port and respond to the request with the response
     87object, writing to its port.
     88
     89The procedure that is requested to be called is looked up in the
     90{{procedures}} argument, which is an alist of procedure name (symbols)
     91to procedure (lambda) mappings. The procedures are called with exactly
     92the arguments that are sent by the client, encoded in the call
     93({{call-sxml}}). They will be converted to regular Scheme values
     94before the procedure is invoked.
     95
     96To determine how XML-RPC types are mapped to Scheme types and
     97vice-versa, see [[#Low-level|below]].  It's important that you read
     98this, because there is some ambiguity in how lists are mapped (either
     99to arrays or to structs).
     100
     101<procedure>(start-simple-xml-rpc-server procedures [port])</procedure>
     102
     103Create a standalone XML-RPC server on {{port}} (defaults to 8080),
     104which accepts an XML-RPC request on any URL.
     105
     106You can also use slightly more low-level procedures to implement your own
     107server to be exactly like you want it to be:
    84108
    85109<procedure>(xml-rpc-call->xml-rpc-response call-sxml procedures)</procedure>
     
    92116the procedure does not exist, or the XML is invalid, a
    93117{{methodResponse}} encoding the {{fault}} is constructed instead.
    94 
    95 {{procedures}} is an alist of procedure name (symbols) to procedure
    96 (lambda) mappings. The procedures are called with exactly the
    97 arguments that are sent by the client, encoded in the call
    98 ({{call-sxml}}). They will be converted to regular Scheme values
    99 before the procedure is invoked.
    100 
    101 To determine how XML-RPC types are mapped to Scheme types and
    102 vice-versa, see [[#Low-level|below]].  It's important that you read
    103 this, because there is some ambiguity in how lists are mapped (either
    104 to arrays or to structs).
    105118
    106119<examples>
     
    349362=== Examples
    350363
    351 A simple "hello" server: (this does not currently function and will be changed)
     364A simple "hello" server:
    352365
    353366<enscript highlight=scheme>
    354367(require-extension xml-rpc-server)
    355  
    356 (define-remote-method (hello var)
     368
     369(define (say-hello var)
    357370  (sprintf "Hello, ~A!" var) )
    358  
    359 ((start-server 4242))
     371
     372((start-simple-xml-rpc-server `((hello . ,say-hello)) 4242))
    360373</enscript>
    361374
     
    364377<enscript highlight=scheme>
    365378(require-extension xml-rpc-client)
    366  
     379
    367380(define srv (xml-rpc-server "http://localhost:4242/RPC2"))
    368381(define hello (srv "hello"))
    369  
     382
    370383(print "-> " (hello "you"))
    371384</enscript>
Note: See TracChangeset for help on using the changeset viewer.