Version 9 of jimhttp

Updated 2014-10-01 06:05:33 by aspect
What jimhttp (name subject to change)
Where https://github.com/dbohdan/jimhttp
Description A web microframework prototype meant to be like Sinatra and Flask written in pure Jim Tcl. Provides a rough implementation of the HTTP protocol as well as routing, templates, JSON generation and parsing, an HTML DSL and persistent storage powered by SQLite3.
Platforms Likely all supported by Jim Tcl's aio .
Prerequisites The latest Jim Tcl from the Git repository . The current stable release (Jim Tcl 0.75) won't do.
Updated 09/2014
License MIT

Code example

source http.tcl

http::add-handler GET /hello/:name/:town {
    return [http::make-response \
            "Hello, $routeVars(name) from $routeVars(town)!"]
}

http::start-server 127.0.0.1 8080

ekd123 - 2014-09-30 08:04:39

Will there be a "tclhttp" written in Tcl?

dbohdan 2014-09-30: It's not a goal for me for now (especially since there are already web frameworks for Tcl) but I would welcome a compatibility patch that makes the code work in both. Porting should be pretty straightforward except for the use of static variables (though static variables can be emulated with namespaces, e.g, by mapping variable varName to $procName::$varName).

aspect 2014-10-01: I just spent an hour or so trying to shim this to run under Tcl (as a Jim learning exercise - nothing more), and while I didn't succeed it certainly looks feasible. A jimshim package would have to do a couple of things:

  • shim set and proc to create the namespace if it doesn't already exist
  • simulate statics as dbohdan describes above
  • extend proc to support TIP#288+ styled arglists, with optional args in the middle. I have a package which approaches this, if anyone's interested.
  • qualify namespaces appropriately -- namespaces in jimhttp aren't explicitly rooted in ::, though it looks like that's how they function
  • do array<->dict binding a la tie to support jim's dict(subscript) notation
  • do a little bit of magic to support the pattern global ns::x; set ns::x. The relative qualified names may make it tricky
  • provide a compatibility wrapper around sqlite3 - just sqlite3.open and the query method are sufficient for jimhttp
  • provide a compatibility wrapper around socket -server
  • provide a stdout command which is almost exactly an alias to fconfigure stdout.

That might be all that's needed. Some (all?) of these are quite trivial edits to the code as it is, but a shim to run it unmodified would be quite nice. Appropriate wrappers for socket and sqlite3 should be trivial in TclOO. If anyone's motivated enough to make a page for Jim Shim and start building a package, I'm happy to contribute what I have so far ... though I have no direct use for it right now, and no real experience with Jim, so quality and support from my end should not be relied upon ;-).

Worth noting: several of jimhttp's modules run perfectly on Tcl without modification. It might be more fun to pull those out and use them with Wibble or Woof! or Rivet or Wub or H . I think that's all the most popular Tcl HTTP stacks today?