Clack

Revenge of Lisp in Web

Chapter 5: Component

English | 日本語

I'm afraid but I told a lie in Chapter 3. --Clack application is just a function--. Honestly, it isn't always a function. See this example.

;; importing symbols for readability.
(import '(clack:call clack:<component>))

(defclass <sample-app> (<component>) ())

(defmethod call ((this <sample-app>) env)
  (declare (ignore env))
  '(200
    (:content-type "text/plain")
    ("Hello, Clack!")))

(clack:clackup
  (make-instance '<sample-app>))

This is much similar to what we've ever seen before, isn't it? The content in a function moved into a method call, and passing an instance of <sample-app> to clackup.

To summarize, clackup can take a function or an instance of a subclass of <component> as an application. All component must have call, it will be called for each requests.

You may not understand how should we handle it yet. I will mention a real example later, so you just remember clackup can take a CLOS instance now.