diff options
author | colin <colin@cicadas.surf> | 2024-05-04 22:09:46 -0700 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2024-05-04 22:09:46 -0700 |
commit | 57afcdd8b437b3ca9b66126db966d07ed751ed15 (patch) | |
tree | 579f80a2f953ed71effbeb3a450e3fcdaedac278 /examples | |
parent | 0b00b8aeadb53abe4cc2bf14d132fe93812b387b (diff) |
dropped defendpoint; added example
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dice-roller.lisp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/examples/dice-roller.lisp b/examples/dice-roller.lisp new file mode 100644 index 0000000..403ed55 --- /dev/null +++ b/examples/dice-roller.lisp @@ -0,0 +1,39 @@ +(defpackage #:dice-roller + (:use #:cl) + (:import-from #:weekend #:endpoint #:handle)) + +(in-package #:dice-roller) + +(defconstant +digits+ "([0-9]+)") + +(defclass roller () + ((rolls + :reader rolls + :initarg :rolls + :type integer + :documentation "The number of rolls") + (sides + :reader sides + :initarg :sides + :type integer + :documentation "The number of sides")) + (:documentation "") + (:metaclass endpoint) + (:method . :get) + (:route-parts "roll" +digits+ "d" +digits+) + (:extractors (:rolls parse-integer) (:sides parse-integer)) + (:content-type . "text/plain")) + +(defmethod handle ((req roller)) + (with-slots (rolls sides) req + (format nil "~ad~a ... rolled a ~a" + rolls sides + (loop :repeat rolls :sum (1+ (random sides)))))) + +(defvar *server* (make-instance 'hunchentoot:easy-acceptor + :port 8080)) + +(hunchentoot:start *server*) + +;; now visit http://localhost:8080/roll/10/d/4 + |