Changeset 15226 in project for wiki


Ignore:
Timestamp:
07/15/09 22:08:08 (10 years ago)
Author:
certainty
Message:

Changes applied for certainty (88.70.194.195) through svnwiki:

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/uri-dispatch

    r15225 r15226  
    1515=== Documentation
    1616
     17Will come soon
     18
     19=== Examples
     20<pre>
     21
     22(use spiffy intarweb uri-common uri-dispatch)
     23
     24(define (my-dispatch-error . path)
     25  (send-status 404 (sprintf "My Dispatch-error ~A" path)))
     26
     27
     28(module example
     29  (echo webiota)
     30  (import scheme chicken srfi-1 extras)
     31  (require-library spiffy)
     32  (import (only spiffy send-status))
     33
     34  (define (webiota #!optional (start "0") (steps "10") #!rest rest)
     35    (send-status 200 (sprintf "webiota called: ~A" (iota (string->number steps) (string->number start)))))
     36
     37  (define (echo . args)
     38    (send-status 200 (sprintf "echo: ~A" args))))
     39
     40(define (outsidemodule . args) (send-status 200 "Outside module"))
     41
     42(vhost-map `(("localhost" . ,(lambda (continue)
     43                              (parameterize ((handle-not-found  (lambda (path) (dispatch-uri (request-uri (current-request)))))
     44                                             (dispatch-error (lambda path (send-status 404 (sprintf "Path not found: ~A" path)))))
     45                                (continue))))))
     46(start-server)
     47
     48</pre>
     49
     50Now start the server and visit the following pages:
     51* http://localhost:8080/example/webiota/2/10/
     52* http://localhost:8080/example/webiota/2/20/
     53* http://localhost:8080/example/webiota/echo/this/please
     54* http://localhost:8080/outsidemodule
     55* http://localhost:8080/i/do/not/exist
Note: See TracChangeset for help on using the changeset viewer.