[plt-scheme] URL-Based Dispatching in the PLT Web Server

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Tue Mar 3 12:27:33 EST 2009

>From http://jay-mccarthy.blogspot.com/2009/03/url-based-dispatching-in-plt-web-server.html

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.

http://faculty.cs.byu.edu/~jay/plt-doc/web-server/dispatch.html

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!

-- 
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay

"The glory of God is Intelligence" - D&C 93


Posted on the users mailing list.