Changeset 15256 in project


Ignore:
Timestamp:
07/25/09 20:00:18 (10 years ago)
Author:
sjamaan
Message:

Give an example of how to use the xml-rpc server under Spiffy.

File:
1 edited

Legend:

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

    r15255 r15256  
    102102<procedure>(make-xml-rpc-request-handler procedures)</procedure>
    103103
    104 This creates a procedure which accepts two arguments; an [intarweb]
     104This creates a procedure which accepts two arguments; an [[intarweb]]
    105105request object and a response object.  It will read an XML-RPC request
    106106from the request-port and respond to the request with the response
     
    411411  -> Hello, you!
    412412
     413The same server, running as a Spiffy vhost request handler:
     414
     415<enscript highlight=scheme>
     416(use spiffy xml-rpc)
     417
     418(define (say-hello var)
     419  (sprintf "Hello, ~A!" var) )
     420
     421(vhost-map
     422  `(("test1" . ,(let ((handler (make-xml-rpc-request-handler
     423                                 `((hello . ,say-hello)))))
     424                  (lambda _
     425                     (handler (current-request)
     426                              (current-response)))))))
     427
     428(start-server)
     429</enscript>
     430
     431When requesting any resource under the host {{test1}}, this will
     432trigger the XML-RPC handler.
     433
     434<enscript highlight=scheme>
     435(require-extension xml-rpc-client)
     436
     437(define srv1 (xml-rpc-server "http://test1:8080/RPC2"))
     438(define hello1 (srv "hello"))
     439
     440(define srv2 (xml-rpc-server "http://localhost:8080/RPC2"))
     441(define hello2 (srv "hello"))
     442
     443
     444;; Prints:
     445;; -> Hello, you!
     446(print "-> " (hello1 "you"))
     447
     448;; Throws an (exn http client-error), with 404 not found:
     449(print "-> " (hello2 "you"))
     450</enscript>
     451
     452If you wish more control over exactly under which URIs the XML
     453resource is available, you could have a look at [[uri-dispatch]], or
     454roll your own URI path checker.
     455
    413456=== Changelog
    414457
Note: See TracChangeset for help on using the changeset viewer.