aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md37
1 files changed, 26 insertions, 11 deletions
diff --git a/README.md b/README.md
index 2279400..4cf2ba0 100644
--- a/README.md
+++ b/README.md
@@ -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