(eighth Racket  Con) Workshop:   Web Programming
1 First Tutorial—It’s all good, or:   As vanilla as it gets
2 Second Tutorial—Hello! & friends
3 Third Tutorial—Input required
4 Fourth Tutorial—Can I have a cookie?
7.1

(eighth RacketCon) Workshop: Web Programming

Jesse Alama <[email protected]>

 (require racketcon-2018-web-devel-workshop)
  package: racketcon-2018-web-devel-workshop

At the (eighth RacketCon), a number of workshops were held. This document covers the tutorials on web programming.

There are four tutorials. Once you’ve installed this package, use raco to launch each of them, like so:

raco 2018-web-workshop first

Doing that launches the first server (or, if you prefer, web application) on your local machine. Instead of first, you can use second, third, and fourth to launch the others.

(This material has been adapted from the first few chapters of my ebook Server: Racket—Practical Web Development with the Racket HTTP Server.)

1 First Tutorial—It’s all good, or: As vanilla as it gets

Wherein we build a web server that does nothing but respond 200 OK to every request it receives.

This sounds trivial. And it is. But the point is to get our feet wet and see what a web server in Racket looks lik.

2 Second Tutorial—Hello! & friends

Wherein we build a web server that greets us in a random language (the body of the response is random), while also giving us, tucked away in the Location header, a URL that tells us its own URL, which isn’t random.

In addition to learning how to modify bits of a "response?", we also learn about the powerful dispatch-rules macro and how it helps us to build URLs.

3 Third Tutorial—Input required

Wherein we build a web server that generates HTML, prompting the user for input, which we duly process.

We learn about include-template, one of the various HTML templating techniques out there.

4 Fourth Tutorial—Can I have a cookie?

Wherein we build a web server that has state in the form of cookies to implement a very basic theme switcher.

We start to use cookies now, an omnipresent technique for recognizability in HTTP (whereby the server can recognize that the request it’s currently processing belongs to a known ‘user‘ or ‘session’. We also look at X-exprs, an alternative to include-template for generating HTML. (We’ll use Matthew Butterick’s txexpr library to help us generate the X-exprs.)