aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2020-11-21 21:43:31 -0600
committerColin Okay <okay@toyful.space>2020-11-21 21:43:31 -0600
commitf1ce4044846296af606a349f47064b4e47691bf0 (patch)
treeda11c1354255590250646f50b9706e929a4558fd
parent442ffcc8637dc92e8a132c1e02b8f00923aeed01 (diff)
added readme
-rw-r--r--README.md81
-rw-r--r--lazybones.lisp2
2 files changed, 82 insertions, 1 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1347780
--- /dev/null
+++ b/README.md
@@ -0,0 +1,81 @@
+# What
+
+`lazybones` is a half-hearted effort at a small HTTP route handling
+framework for smallish dynamic sites, preferably those whose state
+lives in the lisp process.
+
+It is not at all 'field tested', does not compete with more thorougly
+conceived frameworks, and is itself just a kind of wrapper around
+clack.
+
+# Basic Example
+
+``` lisp
+(defpackage #:hello-site
+ (:use #:cl)
+ (import-from #:lazybones
+ #:defroute
+ #:http-ok
+ #:http-err)
+ (import-from #:fictitious-image-db-package
+ #:get-image-ids
+ #:lookup-image
+ #:image-mimetype
+ #:image-data))
+
+(in-package :hello-site)
+
+(defroute :get "/hello"
+ (http-ok "text/html"
+ (spinneret:with-html-string
+ (:doctype)
+ (:html :lang "en"
+ (:head
+ (:meta :charset "utf-8")
+ (:title "some images"))
+ (:body
+ (:h1 "Hello")
+ (:ul
+ (dolist (img-id (get-image-ids)) ; assuming some function to get ids
+ (:li (:img :src (format nil "/image/~a" img-id))))))))))
+
+(defroute :get "/image/:id"
+ (alexandria:if-let (found (lookup-image id)) ; assuming a funciton to lookup images
+ (http-ok (image-mimetype found) ; and to query properties
+ (image-data found)) ; a byte vector
+ (http-err 404 "Not Found")))
+
+
+(start :port 5000) ; start the server
+
+```
+
+Example code that would serve a page containing a list of images.
+
+## Helpful Features
+
+Inside of any handler there is a dynamically bound variable `*req*`
+that holds the HTTP request being processed.
+
+Using a form called `with-handler-preamble`, groups of handlers can be
+defined that all perform some initialization / access control steps.
+
+For example:
+
+``` lisp
+
+(with-handler-preamble
+ ((unless (authorized-request *req*)
+ (http-err 401 "Unauthorized"))
+
+ (make-database-connection))
+
+ (defroute :post "/image/:id/edit"
+ ;; ... handle image post ...
+ )
+
+ (defroute :delete "/image/:id
+ ;; ... handle image delete ...
+ ))
+
+```
diff --git a/lazybones.lisp b/lazybones.lisp
index f7b2235..be20847 100644
--- a/lazybones.lisp
+++ b/lazybones.lisp
@@ -132,7 +132,7 @@ E.G. Consider the form
(http-ok \"text/plain\" \"OK\")
-Outsidef of a DEFROUTE this returns the list
+Outside of a DEFROUTE this returns the list
(200 (:CONTENT-TYPE \"text/plain\" :CONTENT-LENGTH 2) (\"OK\"))