4258e918 |
;; [[file:~/git_repos/lisp-sandbox/todo/README.org::*routing.lisp%20source][routing.lisp source:1]]
;; [[file:~/git_repos/lisp-sandbox/todo/README.org::package-include][package-include]]
|
6543149e |
(in-package :fwoar.todo)
|
4258e918 |
;; package-include ends here
|
7762e7b6 |
;; [[file:~/git_repos/lisp-sandbox/todo/README.org::defroutes][defroutes]]
|
6543149e |
(defmacro defroutes (app &body routes)
(alexandria:once-only (app)
|
4258e918 |
`(setf
,@(loop for (target . descriptors) in routes
append (loop for (method callback) in descriptors
append `((ningle:route ,app ,target
|
9360d164 |
:method ,method)
|
4258e918 |
,callback))))))
|
7762e7b6 |
;; defroutes ends here
|
6543149e |
|
7762e7b6 |
;; [[file:~/git_repos/lisp-sandbox/todo/README.org::routing-helpers][routing-helpers]]
|
6543149e |
(defun success (value)
|
7762e7b6 |
(list 200 '(:conent-type "application/json") value))
|
6543149e |
(defmacro handler ((&optional (sym (gensym "PARAMS"))) &body body)
`(lambda (,sym)
(declare (ignorable ,sym))
(success
|
7cee0702 |
(fwoar.lack.json.middleware:wrap-result
|
6543149e |
(progn ,@body)))))
|
4258e918 |
;; routing-helpers ends here
|
6543149e |
|
7762e7b6 |
;; [[file:~/git_repos/lisp-sandbox/todo/README.org::todo-routes][todo-routes]]
|
4258e918 |
;; routing
|
6543149e |
(defun get-id (params)
(parse-integer (serapeum:assocdr :id params)))
(defun setup-routes (app)
(defroutes app
|
4258e918 |
("/" (:GET (handler () (todos)))
(:POST (handler (v) (new-todo v)))
(:DELETE (handler () (clear-todos))))
("/todo/:id" (:GET (handler (v) (todo (get-id v))))
(:DELETE (handler (v)
(delete-todo (get-id v))
nil))
(:PATCH (handler (v)
(update-todo (get-id v)
(remove :id v :key #'car)))))))
|
7762e7b6 |
;; todo-routes ends here
|
4258e918 |
;; routing.lisp source:1 ends here
|