You are looking at historical revision 15226 of this page. It may differ significantly from its current revision.

Description

uri-dispatch is a simple mechanism to dispatch to uris to procedures. This is useful for webprogramming where you might want to map uris of a certain kind to procedures that implement the logic for those uris.

Author

David Krentzlin

Requirements

Requires the uri-common and environmentsextensions.

Documentation

Will come soon

Examples

<pre>

(use spiffy intarweb uri-common uri-dispatch)

(define (my-dispatch-error . path)

 (send-status 404 (sprintf "My Dispatch-error ~A" path)))

(module example

 (echo webiota)
 (import scheme chicken srfi-1 extras)
 (require-library spiffy)
 (import (only spiffy send-status))
 (define (webiota #!optional (start "0") (steps "10") #!rest rest)
   (send-status 200 (sprintf "webiota called: ~A" (iota (string->number steps) (string->number start)))))
 (define (echo . args)
   (send-status 200 (sprintf "echo: ~A" args))))

(define (outsidemodule . args) (send-status 200 "Outside module"))

(vhost-map `(("localhost" . ,(lambda (continue)

                             (parameterize ((handle-not-found  (lambda (path) (dispatch-uri (request-uri (current-request)))))
                                            (dispatch-error (lambda path (send-status 404 (sprintf "Path not found: ~A" path)))))
                               (continue))))))

(start-server)

</pre>

Now start the server and visit the following pages: