aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-10-15 10:47:56 -0500
committerColin Okay <colin@cicadas.surf>2022-10-15 10:47:56 -0500
commit2dbbd840bb4c0ae0f700d6e894c06e383df2cc01 (patch)
treeaf5a9b66b552847d62562dd26c5893eec71131ba
parentcea91a9edac5fcda2d888521d102efc3695a1cf8 (diff)
Refactor: defendpoint defines a function; easier debugging
-rw-r--r--lazybones.lisp24
1 files changed, 18 insertions, 6 deletions
diff --git a/lazybones.lisp b/lazybones.lisp
index 234340e..5bdd7e6 100644
--- a/lazybones.lisp
+++ b/lazybones.lisp
@@ -358,6 +358,15 @@ any way to do it, hence NIL is returned."
;;; ENDPOINT DEFINITION
+(eval-when (:compile-toplevel :load-toplevel :execute)
+ (defun endpoint-function-name-helper (method route)
+ (string-upcase
+ (format nil "~a-~{~a~^-~}"
+ (symbol-name method)
+ (mapcar
+ (lambda (x) (if (stringp x) x (car x)))
+ (cdr (parse-route-string-template route)))))))
+
(defmacro defendpoint
(appname method route
query-params
@@ -374,6 +383,8 @@ making a new one if not."
(a:with-gensyms (the-app auth-method)
(let* ((dispatch-pattern
(parse-route-string-template route))
+ (endpoint-name
+ (intern (endpoint-function-name-helper method route)))
(lambda-list
(mapcar 'intern (route-variables dispatch-pattern)))
(documentation
@@ -388,6 +399,12 @@ making a new one if not."
(or (app ',appname) (make-instance 'lazybones:app :name ',appname)))
(,auth-method
,auth))
+ (defun ,endpoint-name ,lambda-list
+ (declare (ignorable ,@lambda-list))
+ (setf (lazybones:response-header :content-type)
+ (or ,content-type (lazybones::default-content-type ,the-app)))
+ ,@real-body)
+
(register-endpoint
,the-app
(make-instance
@@ -399,12 +416,7 @@ making a new one if not."
:pattern ',dispatch-pattern
:doc ,documentation
:auth ,auth-method
- :function
- (lambda ,lambda-list
- (declare (ignorable ,@lambda-list))
- (setf (lazybones:response-header :content-type)
- (or ,content-type (lazybones::default-content-type ,the-app)))
- ,@real-body)))))))
+ :function ',endpoint-name))))))
(defmacro defendpoint* (method route params options &rest body)
"Like DEFENDPOINT but uses the current package name as the app name."