Table of Contents
- 1. A simple Hello world with Hunchentoot and Yaclml
- 1.1. Define a package called alien-test
- 1.2. Use the package
- 1.3. Define a global variable
- 1.4. Define two simple functions to stop and start our web server
- 1.5. Create a render-page-wrapper
- 1.6. Define a function say-hello, it has a html tag p
- 1.7. Define another function called hello which will call by dispatcher of hunchentoot
- 1.8. Add the URL '/hello.html' to hunchentoot:*dispatch-table*
- 1.9. Start the web server
- 1.10. Finally open you browser and set the URL
1 A simple Hello world with Hunchentoot and Yaclml
1.1 Define a package called alien-test
;; we need two libraries, so we need load by quicklisp (ql:quickload "hunchentoot") (ql:quickload "yaclml") (defpackage alien-test (:use :common-lisp :asdf :hunchentoot :yaclml))
1.2 Use the package
(in-package :alien-test)
1.3 Define a global variable
(defparameter *server* nil)
1.4 Define two simple functions to stop and start our web server
(defun start-web-server (&key (port 8090)) "Start the web server" (setf *server* (start (make-instance 'easy-acceptor :port port )))) (defun stop-web-server () "Stop the web server" (stop *server*))
1.5 Create a render-page-wrapper
This function generate the basic structure of a web page HTML => HEAD => BODY
(defun render-page-wrapper (title body) (with-yaclml-output-to-string (<:html :doctype "html" (<:head (<:title (<:as-html title))) (<:body :id "body" (funcall body)))))
1.6 Define a function say-hello, it has a html tag p
This function works inside the body tag
(defun say-hello () (<:p "Hello World!"))
1.7 Define another function called hello which will call by dispatcher of hunchentoot
(defun hello () (render-page-wrapper "Hello" 'say-hello))
1.8 Add the URL '/hello.html' to hunchentoot:*dispatch-table*
(setq *dispatch-table* (list (create-prefix-dispatcher "/hello.html" 'hello)))
1.9 Start the web server
(start-web-server)
1.10 Finally open you browser and set the URL
http://localhost:8090/hello.html and you will see the result.
and . . . the code is:
<!DOCTYPE html> <html ><head ><title >Hello</title ></head ><body id="body" ><p >Hello World!</p ></body ></html >