diff --git a/examples/simple-http-client.scm b/examples/simple-http-client.scm new file mode 100755 index 00000000..60f91da2 --- /dev/null +++ b/examples/simple-http-client.scm @@ -0,0 +1,36 @@ +#! /usr/bin/env chibi-scheme + +; Simple HTTP client +; Retrieves the contents of the URL argument: + +; Usage: +; simple-http-client.scm [URL] +; +; Example: +; simple-http-client.scm http://localhost:8000 + +(import (chibi) (chibi net) (chibi net http) (chibi io)) + +(if (> (length (command-line)) 1) + (let ((url (car (cdr (command-line))))) + (if (> (string-length url) 0) + (begin + (display (read-string 65536 (http-get url))) + (newline)))) + (let ((progname (car (command-line)))) + (display "Retrieve the contents of a URL.") + (newline) + (display "Usage:") + (newline) + (newline) + (display progname) + (display " [URL]") + (newline))) + + + + + + + + diff --git a/examples/simple-http-server.scm b/examples/simple-http-server.scm new file mode 100755 index 00000000..744e950a --- /dev/null +++ b/examples/simple-http-server.scm @@ -0,0 +1,16 @@ +#! /usr/bin/env chibi-scheme + +; Simple HTTP server +; Returns a minimal HTML page with a single number incremented +; every request. Binds to localhost port 8000. + +(import (chibi) (chibi net http-server) (chibi net servlet) (chibi sxml)) + +(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: \n") + (p ,count))))))))