"Racket looks great—can I do web devel with it?"
You keep hearing good things about Racket. The team behind it is on a roll: it won the 2018 SIGPLAN Programming Languages Software Award; it's part of the Software Freedom Conservancy; they were recently featured in a cover story for the Communications of the ACM; Racket's core developers not only build and maintain a fantastic language, but consistently crank out top-notch contributions to programming language research and education research, too.
You want to dip your toes in to see what the fuss is all about. But you don't just want to "hack Racket". You want to do web programming. Racket looks great, but can it bring anything to the table for web devel? What does we programming even look like in a language like Racket?
Racket's documentation is really comprehensive, thorough, and helpful. But you're stuck with the official web programming tutorials. They're a start. But things feel scattered. They're just the tip of the iceberg. You want to go further. (What was that jaunt into continuations?)
It doesn't have to be like this. Turns out, those continuations are just one approach.
What if there were a step-by-step tutorial for newcomers that builds a real web site and HTTP API, starting from scratch?
What if you could skip those continuations?
What if you knew the basics by heart and could crank out Racket HTTP apps at will?
Coming March 1, 2019
43 Short Lessons on Web Programming in Racket is an ebook consisting of a series of tutorials that aim to get you up & running with modern web programming in Racket.
It focuses on the the basics, those everyday things you'll need to know no matter how you choose to hack the web with Racket. It definitely does not talk about continuations.
Our project: A bicycle rental web site & HTTP API
In this course, we're going to build a bicycle rental system for the city where we live, running on HTTP.
You live in a city whose mayor wants to launch a new program to try to reduce the number of cars on the road, as well as increase resident fitness: bicycle rentals.
Various little stations will be placed around the city, each containing 10-20 bicycles (the size will vary by how heavily populated, or how busy, that exact part of the city is). Residents will be able to register for the program, upon which they get a chip card. To rent a bicycle, they go to a station, scan their card, and one of the bicycles at that station is offered to them. They drive their bike to whatever station they want to, park it, and leave. The system registers the ride and charges them a certain amount, depending on the time they were away.
There's no attendant at the station; the whole thing is as automated as possible. The bicycles are locked electronically. Upon scanning your card, a bicycle at the station is unlocked. When you arrive, you dock your bike at an available slot, and the bike is automatically locked.
There will be a number of components to this system:
- A web site where residents can inform themselves about the program, register, and (if registered) see their ride history and outstanding balance;
- Another web site where administrators of the system (city employees working in the new Bicycle Department) can monitor the entire system;
- The terminals at each of the dozens of stations are not really web sites in the usual sense (where you visit them with a browser), but they do use HTTP—the underlying communications protocol undergirding the web—to transmit data to the central server indicating that a certain user would like to rent a bike, and upon noticing that someone has parked a bicycle, they again send a message indicating that information.
Since a fresh project, and the mayor is a forward thinking manager, you've been given a green light to use whatever you think the best technology is at hand and to design things you way.
Let's go make our city better— with Racket!
Each headline below is a lesson on a topic in web development, intended to be independent of Racket. The bullet points below a headline are lessons that cover that topic in a Racket-specific way.
1. URIs: Names for things on the web
- 2. The url struct
3. HTTP messages: Request & response
- 4. Can you handle these bytes?
- 5. The request & response structs
6. HTTP servers make the world go 'round
- 7. Making servers with serve/servlet
- 8. dispatch-rules: A DSL for URI-based dispatching
- 9. Serving static content
10. The data of the web, or: The medium of the message
- 11. Setting the MIME type of a response
12. HTML: A markup language for hypermedia
- 13. DIY: format, string-append, ~a & friends
- 14. The handy txexpr library
- 15. Fast templating with include-template
- 17. Using Racket's json library
18. CSS: A language with (and for) style
- 19. Introducing css-expr: A DSL for CSS
- 21. Generating JS with urlang
- 23. xexprs: XML à la Racket
- 25. Generating images dynamically with racket/draw
26. Forms: Input at last
- 27. Handling forms directly
- 28. formlet: An HTML form DSL
29. XmlHttpRequest: The jazzy way to get input
- 30. Handling XmlHttpRequests on the server
31. Cookies: A very tasty header, or: What state is this?
- 32. Generating & accepting cookies with net/cookie
33. Databases: Where data lives after connections die
- 34. Introducing datalog
35. HTTPS: Encrypting your HTTP connection
- 36. Attaching a certificate to your server
37. When servers fail (and they will)
- 38. Testing your servlets with rackunit
- 39. Logging: Getting a bit of visibility into your server
40. No man is an island: Submitting HTTP requests from the server
- 41. Using the http package
42. Authentication: Can you come in? Who are you?
- 43. Adding authentication to a Racket web app
We start with the rock-bottom essentials and, in steps, gradually add complexity as we go along. Armed with this knowledge, you'll be in a strong position to make your next site or HTTP API with Racket.
Editions of the course
Three editions of 43 Short Lessons are available:
This edition includes the book we've been discussing so far.
Includes the Couch Edition and worksheets containing exercises where you can test your knowledge and dig in to the material.
Includes the Library Edition and the instructor's manual, containing
- screencast solutions to all exercises in the worksheets from the Library Edition;
- a list of additional project ideas;
- a discussion of additional Racket libraries & languages that might play a role in more serious projects.
How does this compare to Server: Racket?
I've written another book, Server: Racket, that is also about web devel in Racket. It is understandable to want to compare that book with this course.
Server: Racket is a more advanced book than 43 Short Lessons. I wrote Server: Racket for not only experienced web developers, but those who have a fair amount of experience in Racket, too. Server: Racket is more wide-ranging, "fullstack" book; it is definitely not for Racket newcomers, and it's surely a perplexing read for someone new to web devel.
Server: Racket is also a more traditional tech book. It talks about a potpourri of topics in web devel and explains enough of them in Racket to get you into a position to do things yourself. 43 Short Lessons has a more introductory, pedagogical style. The book is gentler and assumes less knowledge of Racket. In 43 Short Lessons, I explain bits and pieces of Racket as we go along, as well the elements of web development. It is focused on teaching basic HTTP, HTML, and the various technologies that go into the web.
43 Short Lessons even has the optional worksheets, where you can test your knowledge and challenge yourself to go beyond the material, making it your own. Server: Racket is a book and accompanying code, typical of a tech book.
About your teacher
I’m Jesse Alama. I’ve been hacking Scheme, Common Lisp, and (most recently) Racket since 1996. I write about Racket over at lisp.sh. I've written a few Racket books and courses:
- the aforementioned Server: Racket—Practical Web Development with the Racket HTTP Server,
- Racket Weekend, a crash-course on getting started with Racket, and
- Language-oriented Programming in Racket: A Cultural Anthropology, a survey of 31 Racket programmers on what language-oriented programming means to them.
I'm also the author and the author of a few Racket libraries & languages:
- argo (JSON Schema validator),
- json-pointer (RFC 6570: a notation for referring to parts of JSON documents),
- uri-template (RFC 6570: URI Template), and
- riposte (Language for testing JSON-based HTTP APIs)
I’m a coauthor of the entry on the lambda calculus in the Stanford Encyclopedia of Philosophy and worked as a researcher in mathematics and computer science, primarily in automated theorem proving before taking up work as a fullstack web developer. I've taught mathematics, logic, and artificial intelligence in various settings, from high school to graduate-student level. I'm happy to help you get started with Racket, my favorite programming language.
You'll need an account to access this in our app. Please create a password to continue.
Download from the App Store or text yourself a link to the app
Thanks for your support. Now, let's make a Racket on the web!