diff options
author | Colin Okay <okay@toyful.space> | 2022-02-08 15:00:17 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-02-08 15:00:17 -0600 |
commit | 5b77a6c97198d7993eda76c763cff0fd999d94a7 (patch) | |
tree | a15b9a0e71cdae2975b1529f57cbee4e5c22e1ad /README.md | |
parent | 2154ccf238851fe0eff7da33c9792b34d06bbba3 (diff) |
canned error resposnes moved into server api (duh), updated readme
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 37 |
1 files changed, 26 insertions, 11 deletions
@@ -51,9 +51,25 @@ The following is quick example showing a few things that `lazybones` can do. (in-package :lazybones-test) +;; first make a server and add some custom error responses + +(defvar *server* (lzb:create-server :port 8888)) + +(defun custom-404 () + (format nil "~a wasn't found :(" (lzb:request-path))) ; can use request functiosn + +(defun custom-403 () + "You, in particular, can't do that. :P ") + +(lzb:set-canned-response *server* 404 'custom-404 "text/plain" ) +(lzb:set-canned-response *server* 403 'custom-403 "text/plain" ) +(lzb:set-canned-response *server* 500 #p"/path/to/500error.txt" "text/plain" ) + + + + ;; PPROVISION-APP makes an app. You can supply an optional name, a symbol. ;; In lieu of a supplied name, the name of the package is used as the app's name. - (lzb:provision-app () :title "Lazybones Demo App" :version "0.0.0" @@ -61,22 +77,17 @@ The following is quick example showing a few things that `lazybones` can do. endpoints aren't meant to accomplish anything. merely to test out the lazybones HTTP routing framework." - :content-type "text/plain" ; default content type of server responses. - :auth 'post-authorizer ; default authorizor for requests that need it - 404 'custom-404 ; custom content for error response codes. - 403 'custom-403) - -(defun custom-404 () - (format nil "~a wasn't found :(" (lzb:request-path))) - -(defun custom-403 () - "You, in particular, can't do that. :P ") + :content-type "text/plain" ; default content type of server responses. + :auth 'post-authorizer) ; default authorizor for requests that need it (defun post-authorizer () "Request is authorized if it contains the right TESTAPPSESSION cookie. Obtain such a cookie by posting to the /login endpoint." (string-equal "coolsessionbro" (lzb:request-cookie "testappsession"))) +;; now we install the app to the server +(lzb:install-app *server* (lzb:app)) ; (app) is the default app for this package + ;; DEFENDPOINT* is a macro to define an endpoint and install it into the ;; app whose name is the current package anme. DEFENDPOINT (without the *) ;; allows you to explictly specify the app where the endpoint is installed. @@ -152,6 +163,10 @@ The following is quick example showing a few things that `lazybones` can do. (http-ok (jonathan:to-json person))) +;; If you like start the server + +(lzb:start-server *server*) + ``` ## Backends |