diff options
author | colin <colin@cicadas.surf> | 2024-05-05 07:24:40 -0700 |
---|---|---|
committer | colin <colin@cicadas.surf> | 2024-05-05 07:24:40 -0700 |
commit | 1e4235bb162a44bc9474c2fe4851724c41d827a6 (patch) | |
tree | 103f3cef9fed93b538db177062ad783cfa9d4f4b | |
parent | 57afcdd8b437b3ca9b66126db966d07ed751ed15 (diff) |
Fix: route-builder constructor; Modify: dice roller [example]
-rw-r--r-- | examples/dice-roller.lisp | 17 | ||||
-rw-r--r-- | src/endpoint.lisp | 4 |
2 files changed, 15 insertions, 6 deletions
diff --git a/examples/dice-roller.lisp b/examples/dice-roller.lisp index 403ed55..3cd6ac3 100644 --- a/examples/dice-roller.lisp +++ b/examples/dice-roller.lisp @@ -1,6 +1,7 @@ (defpackage #:dice-roller (:use #:cl) - (:import-from #:weekend #:endpoint #:handle)) + (:local-nicknames + (#:wknd #:weekend))) (in-package #:dice-roller) @@ -10,15 +11,17 @@ ((rolls :reader rolls :initarg :rolls + :initform (wknd::slot-required 'roller 'rolls) :type integer :documentation "The number of rolls") (sides :reader sides :initarg :sides + :initform (wknd:slot-required 'roller 'rolls) :type integer :documentation "The number of sides")) (:documentation "") - (:metaclass endpoint) + (:metaclass wknd::endpoint) (:method . :get) (:route-parts "roll" +digits+ "d" +digits+) (:extractors (:rolls parse-integer) (:sides parse-integer)) @@ -31,9 +34,15 @@ (loop :repeat rolls :sum (1+ (random sides)))))) (defvar *server* (make-instance 'hunchentoot:easy-acceptor - :port 8080)) + :port 8888)) (hunchentoot:start *server*) -;; now visit http://localhost:8080/roll/10/d/4 +;; now visit http://localhost:8888/roll/10/d/4 +(ql:quickload :dexador) + +(defun get-roll (rolls sides) + (dexador:get + (concatenate 'string "http://localhost:8888" + (wknd::route-to 'roller :rolls rolls :sides sides)))) diff --git a/src/endpoint.lisp b/src/endpoint.lisp index a0d8f1d..81fdf74 100644 --- a/src/endpoint.lisp +++ b/src/endpoint.lisp @@ -203,10 +203,10 @@ extractors." part)))) (setf build-parts (nreverse build-parts)) (setf (route-builder class) (lambda (kwargs) - (apply #'concatenate 'string + (format nil "~{~a~}" (loop :for part :in build-parts :when (keywordp part) - :do (assert (getf kwargs part) () "path needs ~s" part) + :do (assert (getf kwargs part) (kwargs) "path needs ~s" part) :and :collect (getf kwargs part) :else :collect part)))))) |