Building the Server

Web application development in Scheme is something I’ve just recently gotten into. It’s been a challenging and exciting journey and I’m happy to begin sharing what I’ve learned. I figured I would start with writing a custom web server built from PLT Web Server that serves files and does some basic servlet dispatching.

If you don’t yet have PLT Scheme installed, read my post on Installing PLT Scheme from Source.

PLT Web Server technology allows developers to essentially create their own web servers in scheme. I’m going to start with a basic web server that’s built off of the /usr/plt/collects/web-server/run.ss web server. That will allow us to evolve the code over the course of these articles as we get into some more advanced techniques.

All of the code for this article can be found here: http://alwaysmovefast.com/public_svn/article_src/one/

Go ahead and download it so you can follow along easier and actually run the software on your machine. To run the server:

1. cd into the directory
2. mzscheme
3. (require “main.ss”)

The server should be started now so point your web browser to http://localhost:3000/
and you should see the index.html file.

At this point, I’m not going to go in-depth with what the server is actually doing. For now I’m only going to be talking about building servlets so you shouldn’t have to worry about the server for now.

Go ahead and point your browser at http://localhost:3000/servlets/simple.ss now. The code for this servlet is pretty short:

All you really need to know about this module is that its start function is called when the web server receives a request for it and the request is passed to the start function. The start function then passes back a response to the browser as html.

As a little exercise you could implement your own servlets in the servlets/ directory so you can get a feel for scheme web development.

I’m going to be writing a bunch of follow-up posts on different aspects of scheme web development. The next article is going to be on continuation-based web development. For reference, I’ll be talking about send/suspend and send/suspend/dispatch, so feel free to read up a little on those beforehand.

One Response to “Web Application Development in PLT Scheme - Building the Server”

  1. Web Application Development in PLT Scheme - send/suspend | Always Move Fast Says:

    […] you followed along with my previous posts here and here, you should have scheme installed and ready to go. In your […]

Leave a Reply