Changeset 15226 in project
- Timestamp:
- 07/15/09 22:08:08 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wiki/eggref/4/uri-dispatch
r15225 r15226 15 15 === Documentation 16 16 17 Will 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 50 Now 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.