[racket] Counter servlet

From: Mark Carter (mcturra2000 at yahoo.co.uk)
Date: Wed Oct 13 11:11:37 EDT 2010

> From: Jay McCarthy <jay.mccarthy at gmail.com>

> (a ([href ,what-you-have]) "link text")

OK now guys, now I'm getting seriously excited about the prospect using Racket 
for web servers. I reworked my stateful counter example. Here it is:

#lang racket
;;;; a stateful web server

(require web-server/formlets
         web-server/servlet
         web-server/servlet-env)


(define (counter request (count 0))    
  (send/suspend/dispatch 
   (lambda (k-url)
     `(html (head (title "Counter"))
            (body
             (p "Computer says: " ,(number->string count))
             (a ([href 
                  ,(k-url (lambda (request)
                                (counter (redirect/get) (+ 1 count))))
                  ]) "++")
             (p "Enjoy!"))))))


(define log-file 
  (path->string 
   (build-path (find-system-path 'home-dir) ;(expand-user-path "~") 
               "racket-server-access.txt")))
; would this work better?:
; e.g. (list (build-path "js") (build-path "css"))


;;; Start the server
(serve/servlet counter 
               #:port 8080 
               #:listen-ip #f 
               #:log-file log-file 
               #:servlet-path "/counter.rkt")






Seems to be working fine, too. I am happy about how simple it looks. Some of the 
details about the plumbing magic behind it are a little misty to me, but 
hopefully that will clear up in due course. 


Has anyone managed to install Racket for the Amazon EC2 cloud? I managed to 
compile it on a stock Fedora 8 micro image, but I couldn't quite get make 
install to work. Everything was slow, and I was wondering if it was actually the 
fault of the server itself.



      


Posted on the users mailing list.