[racket] Racket Web Server

From: Danny Yoo (dyoo at cs.wpi.edu)
Date: Sun Dec 11 17:44:50 EST 2011

> I am new to Racket and Lisp/Scheme in general. I am trying to write a simple rest web service in Racket, but I'm not making much progress. Unfortunately, I don't find the Racket docs to be very helpful. I guess my brain just isn't wired right ;-) Asking questions on the mailing list would almost be a step by step at this point, so I thought I would spare y'all from that. Anyway, I'm trying to find some alternative docs or examples. I had the same problem with the Sedna XML stuff, but once I found the scheme docs on Sedna's web site I was able to get going. I've been searching the web for some docs/examples, but no luck so far. Is there anything out there that would help?


Hi Garry,

Just checking: have you already looked at the Web Applications tutorial at:

    http://docs.racket-lang.org/continue/index.html

It should help you get started with the web-server libraries in Racket.


In order to do REST, you'll want to be able to distinguish which
particular HTTP verb is in the request.  You can do this by inspecting
the request structure:

    http://docs.racket-lang.org/web-server/http.html?#(def._((lib._web-server/http/request-structs..rkt)._request))

In particular, I think you'll want to look at the method of a request.
 Here's a quick and dirty example:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
#lang web-server/insta

;; The entry point into our servlet.
(define (start request)

  ;; We'll extract the verb.
  (define method (request-method request))

  ;; and include it as part of our response.
  (response/xexpr
   `(html (head (title "Testing!"))
          (body
           (p "I see the following verb:"
              (br)
              ,(bytes->string/utf-8 method))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Running this program will bring up a server on your local machine that
you can do for local testing.  You can then distinguish GET from POST
by looking at the method.

The other component of a RESTful web service, to use the parameters in
a request, are in functions like extract-binding/single, which the Web
Applications tutorial talks about.

Please feel free to ask questions on the list!



Posted on the users mailing list.