<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div>Here it is (without an imaginative choice of name):</div><div><br class="webkit-block-placeholder"></div><div> <a href="http://planet.plt-scheme.org/display.ss?package=dispatch.plt&owner=untyped">http://planet.plt-scheme.org/display.ss?package=dispatch.plt&owner=untyped</a></div><div><br class="webkit-block-placeholder"></div><div>Dispatch is a tool for configuring controllers in web applications. It's three main functions are:</div><div><br class="webkit-block-placeholder"></div><div>1. providing a mapping from simple, elegant, permanent URLs to controller procedures;</div><div>2. providing a reverse mapping from controller calls to URLs;</div><div>3. providing a simple way to create clean, MVC oriented code without having to worry about cyclic dependencies between modules.</div><div><br></div><div>The example below uses Dispatch and Instaservlet to set up a simple blog:</div><div><br class="webkit-block-placeholder"></div><div>- "site.ss" uses Dispatch to define a simple site with three controllers;</div><div>- "run.ss" uses Instaservlet to configure the PLT web server and create a servlet that dispatches all incoming requests to the site;</div><div>- "posts.ss" provides sample implementations of two of the three controllers and demonstrates non-continuation-based linking between the controllers.</div><div><br class="webkit-block-placeholder"></div><div>The third controller is intentionally left unimplemented to demonstrate Dispatch's default error page, which can be used as a placeholder during development.</div><div><div><div><br class="webkit-block-placeholder"></div><div>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.</div><div><br class="webkit-block-placeholder"></div><div>Cheers,</div><div><br class="webkit-block-placeholder"></div><div>-- Dave</div><div><br class="webkit-block-placeholder"></div><div>===== run.ss =====</div><div><br class="webkit-block-placeholder"></div><div><font class="Apple-style-span" face="Monaco">#lang scheme/base</font></div><div><font class="Apple-style-span" face="Monaco"><br class="webkit-block-placeholder"></font></div><div><font class="Apple-style-span" face="Monaco">(require (planet "instaservlet.ss" ("untyped" "instaservlet.plt" 1))</font></div><div><font class="Apple-style-span" face="Monaco"> (planet "dispatch.ss" ("untyped" "dispatch.plt" 1))</font></div><span class="Apple-style-span" style="font-family: Monaco; "> (file "/posts.ss")</span><div><font class="Apple-style-span" face="Monaco"> (file "site.ss"))</font></div><div><font class="Apple-style-span" face="Monaco"><br>; (request -> response)<br>(define (main request)<br> (dispatch request blog))</font></div><div><font class="Apple-style-span" face="Monaco"><div><div><p align="">(go! main)</p><p align=""><span class="Apple-style-span" style="font-family: 'Lucida Grande'; "><span class="Apple-style-span" style="font-family: Monaco; ">=====</span> site.ss <span class="Apple-style-span" style="font-family: Monaco; ">=====</span></span></p></div></div></font></div><div><span class="Apple-style-span" style="font-family: Times; font-size: 16px; "></span></div><div><span class="Apple-style-span" style="font-family: Times; font-size: 16px; "><span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; "><div><font class="Apple-style-span" face="Monaco">#lang scheme/base<br><br>(require (planet "dispatch.ss" ("untyped" "dispatch.plt" 1)))<br><br>(provide blog index review-post review-archive)<br><br>(define-site blog<br> ([(url "/") index]<br> [(url "/post/" (string-arg)) review-post]<br> [(url "/archive/" (integer-arg) "/" (integer-arg))<br> review-archive]))</font></div><div><font class="Apple-style-span" face="Monaco"><br class="webkit-block-placeholder"></font></div></span></span></div><div><font class="Apple-style-span" face="Times" size="4"><span class="Apple-style-span" style="font-size: 16px;"><span class="Apple-style-span" style="font-family: 'Lucida Grande'; font-size: 13px; "><div>===== posts.ss =====</div><div><font class="Apple-style-span" face="Monaco"><br class="webkit-block-placeholder"></font></div><div><span class="Apple-style-span" style="font-family: Monaco; ">#lang scheme/base</span></div><div><font class="Apple-style-span" face="Monaco"><br class="webkit-block-placeholder"></font></div><div><span class="Apple-style-span" style="font-family: Monaco; ">(require (planet "dispatch.ss" ("untyped" "dispatch.plt" 1))</span></div><div><span class="Apple-style-span" style="font-family: Monaco; "> (file "site.ss"))</span></div><div><font class="Apple-style-span" face="Monaco"><br class="webkit-block-placeholder"></font></div><div><span class="Apple-style-span" style="font-family: Monaco; ">; (request string -> html-response)</span></div><div><span class="Apple-style-span" style="font-family: Monaco; ">(define-controller (review-post request slug)</span></div><div><span class="Apple-style-span" style="font-family: Monaco; "> `(html (head (title ,slug))</span></div><div><span class="Apple-style-span" style="font-family: Monaco; "> (body (h1 "You are viewing " ,(format "~s" slug))</span></div><div><span class="Apple-style-span" style="font-family: Monaco; "> (p "And now for some content..."))))</span></div><div><font class="Apple-style-span" face="Monaco"><div><div><p align="">; (request -> html-response)<br>(define-controller (index request)<br> `(html (head (title "Index"))<br> (body (h1 "Index")<br> (ul ,@(map index-item-html<br> (list "post1"<br> "post2"<br> "post3"))))))<br><br>; (string -> html)<br>(define (index-item-html slug)<br> `(li (a ([href ,(controller-url review-post slug)])<br> "View " ,(format "~s" slug))))</p><p align=""><font class="Apple-style-span" face="'Lucida Grande'">==========</font></p></div></div></font></div></span></span></font></div></div></div></body></html>