From 60b736fc09bc7116a60dd98c0f7d31b2d6bb79d5 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Wed, 9 Feb 2022 14:33:41 -0600 Subject: added let-parameters --- lazybones.lisp | 15 ++++++++++++++- package.lisp | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) 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 -- cgit v1.2.3