From 76d088d2601489001b58d90a68f9ad37bb4bc2c5 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Mon, 6 Jul 2015 23:33:00 +0900 Subject: [PATCH] adding simple example http server to docs --- lib/chibi/net/http-server.scm | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/chibi/net/http-server.scm b/lib/chibi/net/http-server.scm index 152edcf9..681fe85e 100644 --- a/lib/chibi/net/http-server.scm +++ b/lib/chibi/net/http-server.scm @@ -1,15 +1,27 @@ ;; http-server.scm -- combinator-based http server -;; Copyright (c) 2013-2014 Alex Shinn. All rights reserved. +;; Copyright (c) 2013-2015 Alex Shinn. All rights reserved. ;; BSD-style license: http://synthcode.com/license.txt ;;> Runs an http server listening at the given address, with the given ;;> servlet. ;;> -;;> An servlet is a procedure which takes three arguments: an -;;> \scheme{Http-Request} record, which contains the I/O ports and -;;> parsed request and headers; a \scheme{next} procedure to call the -;;> next available servlet if any, and a \scheme{restart} procedure to -;;> restart the servlets with a new request. +;;> An servlet is a procedure which takes four arguments: a +;;> \scheme{(chibi config)} config object, an \scheme{Http-Request} record, +;;> which contains the I/O ports and parsed request and headers; +;;> a \scheme{next} procedure to call the next available servlet if any, +;;> and a \scheme{restart} procedure to restart the servlets with a new +;;> request. +;;> +;;> A simple page view counter could be run as: +;;> +;;> \example{ +;;> (let ((count 0)) +;;> (run-http-server +;;> 8000 +;;> (lambda (cfg request next restart) +;;> (set! count (+ 1 count)) +;;> (servlet-write request (sxml->xml `(html (body (p ,count)))))))) +;;> } (define (run-http-server listener-or-addr servlet . o) (let ((cfg (if (pair? o) (car o) (make-conf '() #f #f #f))))