For a while, untyped has made available their dispatch.plt package on PLaneT. It provides a cool way of parsing and generating URLs for Web applications in PLT.
This week I've taken their ideas and built something into the PLT Web Server: web-server/dispatch.
Take a look at this example from the documentation:
(define-values (blog-dispatch blog-url)
(dispatch-rules
[("") list-posts]
[("posts" (string-arg)) review-post]
[("archive" (integer-arg) (integer-arg)) review-archive]
[else list-posts]))
(define (list-posts req) `(list-posts))
(define (review-post req p) `(review-post ,p))
(define (review-archive req y m) `(review-archive ,y ,m))
> (blog-dispatch (url->request "http://www.chrlsnchrg.com"))
(list-posts)
> (blog-dispatch (url->request "http://www.chrlsnchrg.com/posts/Extracurricular-Activity"))
(review-post "Extracurricular-Activity")
> (blog-dispatch (url->request "http://www.chrlsnchrg.com/archive/1984/10"))
(review-archive 1984 10)
> (blog-url list-posts)
"/"
> (blog-url review-post "Another-Saturday-Night")
"/posts/Another-Saturday-Night"
> (blog-url review-archive 1984 11)
"/archive/1984/11"
Thank you untyped!
0 comments:
Post a Comment