[plt-scheme] Re: ANN: dispatch.plt

From: Dave Gurnell (d.j.gurnell at gmail.com)
Date: Wed Mar 12 06:08:25 EDT 2008

For anyone interested in this library...

The documentation doesn't seem to be showing up on PLanet, so I've  
placed a temporary copy here:

     http://www.davegurnell.com/docs/dispatch.plt/

This is a temporary measure - I'll take it down when the real docs are  
working.

-- Dave

> Here it is (without an imaginative choice of name):
>
>     http://planet.plt-scheme.org/display.ss?package=dispatch.plt&owner=untyped
>
> Dispatch is a tool for configuring controllers in web applications.  
> It's three main functions are:
>
> 1. providing a mapping from simple, elegant, permanent URLs to  
> controller procedures;
> 2. providing a reverse mapping from controller calls to URLs;
> 3. providing a simple way to create clean, MVC oriented code without  
> having to worry about cyclic dependencies between modules.
>
> The example below uses Dispatch and Instaservlet to set up a simple  
> blog:
>
> - "site.ss" uses Dispatch to define a simple site with three  
> controllers;
> - "run.ss" uses Instaservlet to configure the PLT web server and  
> create a servlet that dispatches all incoming requests to the site;
> - "posts.ss" provides sample implementations of two of the three  
> controllers and demonstrates non-continuation-based linking between  
> the controllers.
>
> The third controller is intentionally left unimplemented to  
> demonstrate Dispatch's default error page, which can be used as a  
> placeholder during development.
>
> I haven't added the continuation URL rewriting features that Jay  
> mentioned in the recent discussion on this list. I should be able to  
> add this in a 1.x update without significantly breaking backward  
> compatibility.
>
> Cheers,
>
> -- Dave
>
> ===== run.ss =====
>
> #lang scheme/base
>
> (require (planet "instaservlet.ss" ("untyped" "instaservlet.plt" 1))
>          (planet "dispatch.ss" ("untyped" "dispatch.plt" 1))
>          (file "/posts.ss")
>          (file "site.ss"))
>
> ; (request -> response)
> (define (main request)
>   (dispatch request blog))
> (go! main)
>
> ===== site.ss =====
>
> #lang scheme/base
>
> (require (planet "dispatch.ss" ("untyped" "dispatch.plt" 1)))
>
> (provide blog index review-post review-archive)
>
> (define-site blog
>   ([(url "/") index]
>    [(url "/post/" (string-arg)) review-post]
>    [(url "/archive/" (integer-arg) "/" (integer-arg))
>     review-archive]))
>
> ===== posts.ss =====
>
> #lang scheme/base
>
> (require (planet "dispatch.ss" ("untyped" "dispatch.plt" 1))
>          (file "site.ss"))
>
> ; (request string -> html-response)
> (define-controller (review-post request slug)
>   `(html (head (title ,slug))
>          (body (h1 "You are viewing " ,(format "~s" slug))
>                (p "And now for some content..."))))
> ; (request -> html-response)
> (define-controller (index request)
>   `(html (head (title "Index"))
>          (body (h1 "Index")
>                (ul ,@(map index-item-html
>                           (list "post1"
>                                 "post2"
>                                 "post3"))))))
>
> ; (string -> html)
> (define (index-item-html slug)
>   `(li (a ([href ,(controller-url review-post slug)])
>           "View " ,(format "~s" slug))))
>
> ==========
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20080312/b575131a/attachment.html>

Posted on the users mailing list.