Friday, June 26, 2009

Describing your web application using Swx (take 1)

Update July 05, 2009: Dropped the idea of describing web applications in favour of minimizing cognitive strain and busy work.
Update June 28, 2009: Added the 4th pattern with default params.



require '/path/to/swx.php';
requires ('handlers');

'POST /{handler}',
'GET {handler} /foobar',
'/.* handler=default,id=1'



Anonymous said...


This makes routes quite easy to specify.

Why do you do {[id]}, why not just [id].

A portion of your dsl here is parsed out of a string. I usually tend towards keeping my dsls as far as possible in code.

My lisp way of doing it would be:

(route POST /{handler})
(route /{handler}/[id])
(route GET {handler}

It's almost the same in many ways.

This would be nice too:

(route GET {handler}[id]/{visiting-card})

in which two handlers (handler and visiting-card) get called.

Or even:

(route GET
#'(lambda (name) (format t "You are at ~a!" name))
#'(lambda (id) (using-person id (format t "hello ~a~%" name))))

in which the handlers is defined inline. The url that hits this route of course is

How about:

* POST / {handler}
* / {handler} / [id]
* GET {handler} /foobar
* GET {handler} /person/ [id]
* GET {handler} /person/ [id] / {visiting-card}
#'(lambda (name) (format t "You are at ~a!" name))
#'(lambda (id) (using-person id (format t "hello ~a~%" name))))

I think lisp can handle that. It's very much in the fashion of the powerful loop macro (see

Sandeep Shetty said...

> Why do you do {[id]}, why not just [id].

Its actually [{id}]. The braces are needed to capture the variable id and the square brackets make it optional.