I am wondering how my application, written in Common Lisp, will serve pages for the web client.
Hunchentoot serves everything that is in *dispatch-table* , which is just a list of dispatch handlers.
The simplest task is to maintain a static file. One typical example is a CSS file:
(push (create-static-file-dispatcher-and-handler "/example.css" "example.css") *dispatch-table*)
For a web application, you most likely want to dynamically create a web page. You do this by defining a function that returns the page as a string (for example, with CL-WHO), then creating a handler for this function:
(defun foo () (with-html-output-to-string ; ... )) (push (create-prefix-dispatcher "/foo.html" 'foo) *dispatch-table*)
You can eliminate many patterns through macros, by the way:
(defmacro standard-page ((title) & body body)
`(with-html-output-to-string (* standard-output * nil: prologue t: indent t)
(: html: xmlns "http://www.w3.org/1999/xhtml"
: xml \: lang "de"
: lang "de"
(: head
(: meta: http-equiv "Content-Type"
: content "text / html; charset = utf-8")
(: title, title)
(: link: type "text / css"
: rel "stylesheet"
: href "/example.css"))
(: body
, @ body))))
(defmacro defpage (name (title) & body body)
`(progn
(defmethod, name ()
(standard-page (, title)
, @ body))
(push (create-prefix-dispatcher, (format nil "/~(~a~).html" name) ', name)
* dispatch-table *)))
The examples you provided should be sufficient to get started, and if you encounter any problems, read the manual and ask specific questions.
source share