httpd (Tcllib)

httpd is a package included in Tcllib. It implements a TclOO and coroutine-based HTTP server in pure Tcl. The project started as adapting minihttpd.tcl included with TclHttpd to use TclOO and coroutines. In the end it took on a life of it's own. The idea with the module is that it simply provides all of the plumbing that a developer would need to embed and HTTP listener implementation into his/her program. It's not a standalone web server.

However, there is a standalone web server that is build on top of Httpd: Toadhttpd.

# Example of how to use httpd
package require httpd 4.0
httpd::server create HTTPD port 8015
# Open our port
HTTPD start

# Add in a dict based dispatcher
HTTPD plugin dispatch ::httpd::plugin.dict_dispatch
# Register the /hello uri to be answered by our new class
HTTPD uri add * /hello {mixin {content reply.hello}}

oo::class create ::reply.hello {
  method content {} {
my puts "<HTML><HEAD><TITLE>My Example Server</TITLE></HEAD><BODY>"
my puts "<h1>Hello World!</h1>"
my puts "Nice to see you from [my request get REMOTE_HOST]"
my puts "The time is now [clock format [clock seconds]]"
my puts </BODY></HTML>
  }
}