[Lispweb] More Araneida testing features: with-url-params and defurlmethod

Alan Shields Alan-Shields at omrf.ouhsc.edu
Sat Oct 1 21:01:33 CDT 2005


Hello everyone,

In a project I'm working on, it made sense to treat url parameters as
method parameters for multi-method-dispatch (like defmethod), so I wrote
defurlmethod that allows you to do that.

Example:

(defurlmethod foome (handler method request
                             &require bim
							 &key (baz "default value for baz"))
  (format nil "bim: ~A, baz: ~A" bim baz))

(defmethod handle-request-response ((handler my-handler) method request)
  (html-stream (request-stream request)
    `(html (body (p (foome handler method request))))))


If there was at least some value for bim, it would work. Otherwise there
would be no match.

So you could do:

(defurlmethod foome (handler method request)
  (format nil "Needed parameters not given!"))

to have a default.

You can do more than that, though:

(defurlmethod foome (handler method request
                             &require (bim (string-equal "bozo"))
							 &key (baz "shout"))
  (format nil "You bozos are always ~A-ing all the time" baz))

When (string-equal bim "bozo") is true, this method will be called.

This is a short introduction, the full docs are in defurlmethod.lisp,
especially in the docstring for defurlmethod.

deftaintedurlmethod is there as well, and does pretty much what you'd
think.

In the process of writing all this, I wrote (with-url-params
(parameters) (request-url request) ...)

It binds the value of the parameter (matched case-insensitively) to its
url parameter counterpart.

with-tainted-url-params exists as well.

There's sample code in the test suite. I hope it's pretty easy to follow
- I try to write for clarity.

This will be going into the next version of Araneida, which I'm thinking
needs a version bump. Any sugggestions?

Thanks, and I hope you find this useful,
Alan

Darcs repository:
http://code.microarray.omrf.org/darcs/alan-araneida-testing/
Browseable darcs repository:
http://code.microarray.omrf.org/cgi-bin/darcs.cgi/alan-araneida-testing/?c=browse




More information about the lispweb mailing list