[plt-scheme] Module-based web servlet examples (SUMMARY)

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Tue Oct 17 18:19:12 EDT 2006

On 2006 Oct 17 , at 17.48, Jay McCarthy wrote:

> On 10/17/06, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
>> > There might still be a mismatch.  That page documents the 'request'
>> >     (define-struct request (method uri headers/raw bindings/raw
>> >                                  host-ip host-port client-ip))
>>  > Ought I to be worried by the mismatch?  I think this is being  
>> included
>>  > by servlet.ss, via servlet-structs.ss, if I'm interpreting the  
>> module
>>  > loading semantics correctly.
> The documentation describes the public API. Internally are the /raw
> versions of headers and bindings.

...and it's presumably not request-structs.ss that I should be  
including, but just servlet.ss.  Righto -- that makes pleny of sense.

Use the docs, Luke.

I'll include the version which finally worked for me here, for the  
archive.  I wonder if this might this be a useful non-trivial example  
of a module-based servlet, for the documentation or distribution.

(module echoing-servlet mzscheme
    (provide interface-version timeout start)

    (require (lib "servlet.ss" "web-server")
             (lib "url.ss" "net"))

    (define interface-version 'v1)

    (define timeout 10)

    ; start : request -> response
    (define (start rq)
      (report-errors-to-browser send/finish)
        (head (title "Echo servlet"))
         (h1 "Echo servlet")
          (tr (td "Current directory")
              (td ,(format "~s" (current-directory))))
          (tr (td "method")
              (td ,(symbol->string (request-method rq))))
          (tr (td "headers")
              (td (table ((border "1"))
                   ,@(map (lambda (p)
                           `(tr (td ,(symbol->string (car p)))
                                (td ,(cdr p))))
                          (request-headers rq)))))

          ;; "net" package url structure documented at
          ;; http://pre.plt-scheme.org/plt/collects/net/doc.txt
          (tr (td "uri")
              (td ,(format "~s"
                           (map (lambda (pp)
                                  (cons (path/param-path pp)
                                        (path/param-param pp)))
                                (url-path (request-uri rq))))))

> BTW Jens, thanks for answering these questions so well.

Ditto, in spades.

All the best,


Norman Gray  /  http://nxg.me.uk
eurovotech.org  /  University of Leicester, UK

Posted on the users mailing list.