From 49f8cafff4b63ebb7c0fa3bfc182072d8d5197ea Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Sun, 13 Feb 2022 19:38:51 -0600 Subject: Made 200 response the default. http-err now singals condition --- example/lazybones-example.lisp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'example/lazybones-example.lisp') diff --git a/example/lazybones-example.lisp b/example/lazybones-example.lisp index 1efc882..88a58a1 100644 --- a/example/lazybones-example.lisp +++ b/example/lazybones-example.lisp @@ -5,7 +5,6 @@ (:local-nicknames (#:lzb #:lazybones)) (:import-from #:lazybones #:defendpoint* - #:http-ok #:http-err)) (in-package :lazybones-example) @@ -60,21 +59,21 @@ to 'coolsessionbro'." (print (lzb:request-body)) ; dummy implementation, prints post body to stdout (setf (lzb:response-cookie "testappsession") "coolsessionbro") - (http-ok "true")) + "true") ;; The next route defines a route variable WHO (defendpoint* :get "/hello/:who:" () () "Echos back Hello WHO" - (http-ok (format nil "Hello ~a~%" who))) ; use the route variable here + (format nil "Hello ~a~%" who)) ; use the route variable here (defendpoint* :post "/hello/:who:" () (:auth t) ; use the app's default authorizor "Echo's back 'Hello WHO, I got your message BODY' where BODY is the post body." (print (lzb:request-header :content-type)) (let ((body (lzb:request-body))) - (http-ok (format nil "Hello ~a, I got your message ~a~%" - who body)))) + (format nil "Hello ~a, I got your message ~a~%" + who body))) ;; Some helpers, these are used to parse url variables and query ;; parameters. Their docstrings are used in the API documentation @@ -92,7 +91,7 @@ ;; 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))) + (format nil "Name: ~a~%age: ~a~%" name age)) (defun crapshoot-authorizer () "Randomly decides that the request is authorized" @@ -101,16 +100,15 @@ (defendpoint* :post "/crapshoot" () (:auth 'crapshoot-authorizer) ; use a custom authorizer "Echos back 'You made it' if the request was authorized" - (http-ok "You made it")) + "You made it") ;; 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) - (http-ok - (format nil "The number is: ~a~%" - (+ lo (random (- hi lo))))) + (format nil "The number is: ~a~%" + (+ lo (random (- hi lo)))) (http-err 404))) ; Can't find a number X such that LO >= HI and LO < X < HI (defun person-by-id (id) @@ -124,6 +122,5 @@ (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))) + (jonathan:to-json person)) -- cgit v1.2.3