diff options
author | Colin Okay <okay@toyful.space> | 2022-02-09 14:33:41 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-02-09 14:33:41 -0600 |
commit | 60b736fc09bc7116a60dd98c0f7d31b2d6bb79d5 (patch) | |
tree | 65e36083ad0eb43b8511de8ec477cb8fd1006bdb | |
parent | 6225e142525d02888d0a1aa83fb716ddb58db907 (diff) |
added let-parameters
-rw-r--r-- | lazybones.lisp | 15 | ||||
-rw-r--r-- | package.lisp | 1 |
2 files changed, 15 insertions, 1 deletions
diff --git a/lazybones.lisp b/lazybones.lisp index c04e1e4..2b28be7 100644 --- a/lazybones.lisp +++ b/lazybones.lisp @@ -364,7 +364,20 @@ making a new one if not." `(defendpoint ,(default-app-name) ,method ,route ,options ,@body)) -;;; utilities + + +;;; ENDPOINT HANDLING UTILITIES + +(defmacro let-parameters ((&rest names) &body body) + "NAMES is a list of symbols. Binds the names to the value of the +request parameters whose keys compare string-equal to the symbol-name +of each NAME, or NIL if there is no such parameter." + (let ((params (gensym))) + `(let ((,params (lazybones:request-parameters))) + (let ,(loop for name in names + for string-name = (symbol-name name) + collect `(,name (cdr (assoc ,string-name ,params :test #'string-equal)))) + ,@body)))) (defun http-ok (content) "Content should be a string, a byte-vector, or a pathname to a local diff --git a/package.lisp b/package.lisp index 22de31b..64b0649 100644 --- a/package.lisp +++ b/package.lisp @@ -51,6 +51,7 @@ #:defendpoint #:defendpoint* #:endpoint + #:let-parameters #:http-err #:http-ok #:http-respond |