Tips, tricks, articles, and tutorials for getting the most out of Racket. By Jesse Alama.


URL lookup with koyo/url

Racket’s built-in dispatch-rules macro is a powerful way to set up routes for your web app. But there’s one big disadvantage. koyo’s dispatch-rules+roles and reverse-uri are a powerful alternative that you should know about.

[wait, what was the URL again?]

koyo: Racket web programming superpack

The koyo package is a boon to Racket web development. It contains a fantastic collection that pretty much any serious Racket web app is going to want to use. And if you want to go your own way, that’s fine: koyo’s components are mix-and-match. If you’ve been wanting to get into Racket web programming, this is a great way to get started. If you’ve done some Racket web programming before and found it hard to approach, knowing about koyo may be just what you need to help you go forward.

[Racket web devel, many batteries included]

Using an escape continuation to keep fussy code more readable

Escape continuations are a control operator that lets you “prematurely” exit from a block of code. If you’ve ever wondered whether Racket has a return statement, take a look.

[get me out of here!!]

Some notes for deta newbies

Some notes on getting started with deta, a delightful minimal Racket ORM (object-relational mapper). Here are a few avoidable pitfalls I fell into.

[show me the models!]

My (very!) short review of Racket in 2020

2020 was a pretty wild year. Here’s what I saw happening in the Racket world.

[2020? Ugh.]

Announcing: Racketfest 2020

The next edition of Racketfest, the little European Racket conference that could, will be held in Berlin, Germany, on February 27, 2020.


Coming soon: Summer Racketfest 2019!

Racketfest is a one-day conference to have some fun diving in to Racket with fellow Racket programmers. The next edition will be held on August 17, 2019. Come join us!

[warm up to Racket]

A language for stateless web programs

Racket’s web-server language for stateless web programs is a brilliant example of language-oriented programming. “But it’s just Racket.” Take a closer look.

[a web of language-oriented programming]

A précis of the first Racketfest

Racketfest is a new conference I organized for Racket programmers to have meet each other, have some fun, and sharpen their skills.

[fe(a)st of Racket]

New in 7.3: Default HTTP response status messages

As of Racket 7.3, the Racket web server now comes with a bunch of default HTTP response status messages. You no longer need to supply them; sensible defaults, inferred from the HTTP status code, will be used.

[200? OK.]

Where does the Racket web server store continuations?

For web server continuations to work, there needs to be some way to store them, right? Where are they?

[uncover them]

How to think about web programming with continuations

Continuations are hard. It may not be clear how they apply to web programming. Here’s a 30000 foot view.


New book coming soon: A Short Introduction to Web Programming with Continuations in Racket

Having trouble grokking how continuations make sense for web programming? I’m working on a book to help with that.

[continue this]

Announcing: Racketfest 2019

I’m organizing a Racket conference, to be held in Berlin, Germany, on March 23, 2019.


Language-oriented Programming in Racket: A Cultural Anthropology is now available

In which I survey 30 Racket programmers to find out how they understand “language-oriented programming”

[wtf is “language-oriented programming”?]

In the beginning there was request? → response?

Racket’s approach to doing web programming is straightfoward: you receive a request (a structure consisting of a number of parts, such as the URL and the HTTP method) and your job is to build a response (another structure). The web server reads the connection and gives you a request; upon receiving your response, the server will pass it along the connection. Functions from requests to responses are called servlets. Here’s how you can get started with the Racket way of doing HTTP.

[learn the servlet way]

Racket Weekend is now live

Racket Weekend, a short course in getting started with the Racket programming language, is now live.

[what are you doing this weekend?]

Fast HTML templates for Racket servlets with include-template

You’ve got a lot of options when it comes to generating HTML in Racket, each with their own (dis)advantages. In this tutorial, we discuss include-template, part of the built-in web server, which generates HTML quickly and statically.

[(include include-template your-racket-html-toolbelt)]

Practical HTML generation in Racket servlets with txexpr

Why is it so hard to generate HTML with Racket? What's the right way to do it? Although the ideal library may not (yet) exist, you can come pretty close with Matthew Butterick's txexpr library. Here's how to get started.

[generate HTML without crying]

How to generate a Location header

A Location HTTP response header is used by browsers and non-browsers alike to indicate where to find a previously created or updated resource. Here’s how you can generate a Location header in Racket.

[where am I?]

Server-side cookie processing in Racket

Cookies are a bread-and-butter technique for preserving state across HTTP requests. If you don’t want to use continuations in your Racket web apps but still have a halfway workable concept of state, cookies are how you can achieve this. Here’s how you can read and generate cookies using the Racket web server.

[put your hand in the cookie jar]

27.5 Racket packages for web devel

Is Racket ready for web development? Here are some useful packages to keep in your web programming toolbox.

[hack the web with Racket]

Object-relational mapping in Racket with Racquel

Object-relational mapping is a technique for making a correspondence between entries in a relational database (such as MySQL or Postgres) and objects in a system runtime. The relationship is maps tables to classes. This is often a useful (if at times less-than-ideal) approach to working with relational databases in code. Here’s how you can do that in Racket with Racquel.

[map my objects]

Validate JSON input with JSON Schema

Receiving JSON inputs over an HTTP API is a common way of designing a web site. Many common checks for making sure that your data has the intended structure (this is an integer, that is a string, there are no superfluous inputs, etc.) can be carried out using JSON Schema. Here’s how you can do that in Racket.

[check your JSON]

Functionally rewriting HTTP requests and responses with struct-copy

Manipulating HTTP requests and responses is a common need in web sites and HTTP APIs. Here's a straightforward way to do that, in a functional way, in Racket.

[rewrite HTTP with gusto]

Argo: JSON Adventures in JSON Schema

You know the feeling: you’re working with JSON data and need to make sure that it adheres to some sensible constraints. JSON Schema is a sensible way to ensure that. Argo is a Racket library for validating JSON data using JSON Schema.

[validate JSON]

Get the original request, no matter where you are

When dealing with complicated requests, it sometimes help to know the URL of the request that got you where you landed. If the request is an argument to your function, it’s clear what needs to be done. But what if it’s not? Here’s a Racket-y way to get the information you need.

[get original requests]

How do you get the ID of the row created by an INSERT using Postgres?

How do you get the ID of the row you just inserted into your Postgres table? There’s an elegant technique that will give you exactly this information. And if you don’t know about query placeholders yet, now is a good time to get up to speed.

[make Postgres RETURNING what you want]

Logging web server events in Racket to syslog

Logging is crucial for keeping tabs on a web site. Here's a simple guide to getting started with Racket's nice logging system, which addresses one gotcha that might explain why you aren't seeing anything from Racket in the system log.

[learn to love logging]

Production vs. development environments for the Racket HTTP server

When developing a site, it’s useful to be able to distinguish between production (server is live) vs. development (server is not live). In development, the server should behave slightly differently: it might generate more verbose debugging output, use different configurations for connecting with external services, and so on. Here’s a simple way to do that in Racket using environment variables and parameters.

[go live…or not]

Installing a fallback error handler for your Racket web app

True story: that sweet Racket servlet you wrote probably has errors. Here’s how you can install a fallback error handler for your Racket web app to make sure that you log those unexpected problems that are bound to arise, and then bow out gracefully to your users with a clean HTTP response.

[fall back to safety]

Convenient, thread-safe database connections for your Racket web site

When building a web site with Racket, you may find yourself needing to communicate with a relational database (MySQL, Postgres, etc.). If each request gets handled in a separate thread, how do you make sure that your database connections are isolated from each other? Here's how you work with databases robustly using Racket.

[get thread-safe]

How to deploy a Racket web site to Ubuntu Linux with Apache

Now that you’ve made a Racket-based web app, how do you deploy it? Using Ubuntu and Apache is a straightforward approach. Here’s a step-by-step guide to pushing your Lisp live.

[learn more]

CRUD web APIs using the Racket web server

Writing CRUD (create, read, update, delete) web applications with Racket is great fun. Getting started, though, can be difficult. The documentation is overwhelming. Here’s some starter code for a simple database-style web service that maintains a hash table, which offers resources in JSON.

[get your CRUD on]

How to use raco in Docker: Needed Ubuntu packages

When running raco in an Ubuntu-based Docker container, there are a couple of packages you'll need if you want to use raco inside the container.

[apt-get read more]

How do I fetch a URL in Racket?

Simple HTTP operations, such as simply doing an HTTP GET on a URL, are a bit fussy in Racket. Here’s a code snippet that can simplify things.

[GET going]

Does the memory usage of the Racket web server balloon if you don’t use continuations?

When building a web application using the Racket web server modules, it's clear that, if you use continuations, your web server's memory footprint will grow over time. But what if you're not using continuations?

[save memory]

How do I get the URL of the current request?

Whether you’re using stateful or stateless servlets, you sometimes want to know what the URL of the current request is. Here’s how you can get it.

[give it to me]

URL dispatching in Racket without continuations

Confounded by continuations? It can seem that building even a simple web application in Racket requires you to use a fairly advanced programming concept. Here's how you can make a web application in Racket using traditional URL-based dispatching based on routes. Starter code included.

[route me in]

Make Emacs use Racket mode for files with non-standard extensions

You’d like to use Emacs to hack Racket code, but your file does not have a standard .rkt extension. Here’s how to get Emacs to switch to Racket mode based on the contents of the file rather than its extension.

[detect Racket]

How to balance parentheses in DrRacket

DrRacket is pretty great. But it seems to be missing an obvious feature: balanced parentheses. The feature is actually there, if you know where to look.

[get balanced]

Where should I keep my Racket snippets?

“This function is pretty sweet, I bet others would find this useful.” What’s the Racket-y way to store and share your Racket code snippets?

[paste away]

Where does DrRacket look for files?

DrRacket and racket on the command line might behave differently when it comes to process, system, and friends. What's going on? A good place to start is the environment. Three tips for making sure these differences don't bite you.

[take the PATH less traveled]

Do hash-key and hash-values give their results in the same order?

When working with hash tables, is it safe to assume that the list that hash-keys returns has the same order as the list returned by hash-values? Answer: No.

[learn more]