In this chapter, I would like to introduce
Clack.Builder, or the most common
way to use Clack middlewares. Clack.Builder calls middlewares’
wraps sequentially and returns a function, which you can use as a
The syntax of Clack.Builder is easy:
(builder ;; Write Middleware classes here. #'app) ;=> Function (as an Application)
(import 'clack.builder:builder) (defun app (env) (declare (ignore env)) '(200 (:content-type "text/plain") ("Hello, Clack!"))) (clack:clackup (builder <clack-middleware-session> (<clack-middleware-static> :path "/public/" :root #p"/path/to/static-files/") #'app))
<clack-middleware-session> is a middleware for session management, which adds
env and enables you to handle sessions as a hash
for the details.
wraps from bottom to top. In this example,
is wrapped by
<clack-middleware-static> first, and the resulting entity is
Let’s take a look at the figure in Chapter 7 again.
In terms of this figure,
<clack-middleware-session> is the outer middleware,
<clack-middleware-static> is the inner one.