[racket] Web server and URL dispatch

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Fri Dec 2 23:44:41 EST 2011

http://docs.racket-lang.org/web-server/run.html#(part._.Examples)

contains this...

>>>
Suppose you wanted it to capture top-level requests:

(serve/servlet my-app
               #:servlet-regexp #rx"")
<<<

Where do you think a different example should go? Somewhere on

http://docs.racket-lang.org/web-server/dispatch.html

?

On Fri, Dec 2, 2011 at 8:15 PM, Jordan Schatz <jordan at noionlabs.com> wrote:

> On Fri, Dec 02, 2011 at 06:23:38PM -0700, Jay McCarthy wrote:
> > The blog-dispatch function returned by dispatch-rules has the contract
> > "request? -> response?" so you pass it in in place of "start" to
> > serve/servlet:
> >
> > (serve/servlet blog-dispatch ...)
> >
> > It is not a "dispatcher" in the Web server's terminology. That's a
> > "connection? request? -> void" function and only low level functions use
> > those.
>
> ----------------------------------------------------------------------
> #lang web-server
>
> (require web-server/dispatch
>         web-server/servlet-env)
>
> (define-values (blog-dispatch blog-url)
>  (dispatch-rules
>   [("") list-posts]
>   [("posts" (string-arg)) review-post]))
>
> (define (list-posts req)
>  (response/xexpr
>   `(body "list-posts")))
>
> (define (review-post req p)
>  (response/xexpr
>   `(body ,(string-append "review-posts " p))))
>
> ;; ;; Doesn't work
> ;; (serve/servlet blog-dispatch
> ;;                #:port 8080
> ;;                #:launch-browser? #t)
> ;; ;; Doesn't work
> ;; (serve/servlet blog-dispatch
> ;;                #:port 8080
> ;;                #:servlet-path "/"
> ;;                #:launch-browser? #t)
> ;; Works
> (serve/servlet blog-dispatch
>               #:port 8080
>               #:servlet-regexp #rx".*" ;But is this "the right way"?
>               #:launch-browser? #t)
> ----------------------------------------------------------------------
>
> Once I got it working, it makes sense; but maybe a more complete example
> could be added to the docs?
>
> Shalom,
> Jordan
>



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

"The glory of God is Intelligence" - D&C 93
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111202/a7800576/attachment.html>

Posted on the users mailing list.