httpd (Tcllib)

Difference between version 3 and 4 - Previous - Next
'''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 httpdpackage require httpd 4.01
httpd::server create HTTPD port 8015

# 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 [list mixin {content reply.hello}]

clay::define ::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>
  }
}

# If not in interactive modevwaputs [list fLISTENING on [HTTPD port_listevening]]
cron::main
======


   * [https://core.tcl.tk/tcllib/doc/trunk/embedded/www/tcllib/files/modules/httpd/httpd.html%|%Manual page]
   * [Toadhttpd] - A project that extends this module into a fully working web server
<<categories>> Tcllib | Web