aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2022-02-12 14:33:25 -0600
committerColin Okay <okay@toyful.space>2022-02-12 14:33:25 -0600
commit3ba4da76e44e61e78a04aadcc88853e2ddee5d13 (patch)
tree886758aceb5f2be62a566bead37a12398eec5434
parent6d229370f83d984a1d31b2fcd3e00fcb721a7b8e (diff)
comments to example
-rw-r--r--example/lazybones-test.lisp14
1 files changed, 11 insertions, 3 deletions
diff --git a/example/lazybones-test.lisp b/example/lazybones-test.lisp
index 3c04065..aca7a56 100644
--- a/example/lazybones-test.lisp
+++ b/example/lazybones-test.lisp
@@ -52,6 +52,8 @@
;; app whose name is the current package anme. DEFENDPOINT (without the *)
;; allows you to explictly specify the app where the endpoint is installed.
+;; The general syntax is: DEFENDPOINT* HTTP-METHOD ROUTE-TEMPLATE QUERY-PARAMETERS OPTIONS DOCSTRING BODY ...
+
(defendpoint* :post "/login" () ()
"Dummy login endpoint for returning a session cookie. Always returns
the \"true\" and sends a set-cookie header, setting 'testappsession'
@@ -60,9 +62,11 @@
(setf (lzb:response-cookie "testappsession") "coolsessionbro")
(http-ok "true"))
+
+;; The next route defines a route variable WHO
(defendpoint* :get "/hello/:who:" () ()
"Echos back Hello WHO"
- (http-ok (format nil "Hello ~a~%" who)))
+ (http-ok (format nil "Hello ~a~%" who))) ; use the route variable here
(defendpoint* :post "/hello/:who:" () (:auth t) ; use the default authorizor for the app
"Echo's back 'Hello WHO, I got your message BODY' where BODY is the post body."
@@ -82,6 +86,9 @@
"A String"
string)
+;; In the following, two query parameters are specififed. NAME is
+;; meant to be a string and AGE is an integer. If AGE is not an integer,
+;; a 500 error will be returned. The syntax is (VAR PARSER)
(defendpoint* :get "/search" ((name str) (age int)) ()
"Echo the search parameters in a nice list."
(http-ok (format nil "Name: ~a~%age: ~a~%" name age)))
@@ -96,7 +103,6 @@
;; Route variables can accept parsers / preformatters
;; these will parse a value and supply it to the argument of the handler.
-
(defendpoint* :get "/random/:lo int:/:hi int:" () ()
"Echo back a random number between lo and hi"
(if (< lo hi)
@@ -112,7 +118,9 @@
;; 500 response would be sent to the client.
(list :name "Colin" :occupation "Macrologist" :id (parse-integer id)))
-(defendpoint* :get "/person/:person person-by-id:" () (:content-type "application/json")
+
+(defendpoint* :get "/person/:person person-by-id:" ()
+ (:content-type "application/json") ; override the app's default content type for HTTP responses
"Returns a json representation of the person."
(http-ok
(jonathan:to-json person)))