couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Davies <ja...@jasondavies.com>
Subject Re: Webmachine dispatcher example
Date Fri, 08 May 2009 00:15:53 GMT
On 7 May 2009, at 18:50, Jason Davies wrote:

> On 7 May 2009, at 18:33, Justin Sheehy wrote:
>
>> I've now changed the dispatcher such that it should be useful outside
>> of webmachine without affecting internal use.

[snip]

> This looks great, thanks very much!  I'll let you know how I get on.

Okay, here's a first stab at this: http://github.com/jasondavies/couchdb/commit/f6cb4012269e5331c5bf95077a00a4a09c9ea029

The basic idea is you add "rewrites": [...] member to the design doc.   
This is a list of rewrite rules of the form: {"match": [...],  
"rewrite": [...]}.  The "match" member is a list of path tokens to be  
matched.  The "rewrite" member specifies the target path, also as a  
list of path tokens.

The match tokens can be either "foo" (specific match of "foo"),  
":foo" (any token, can be captured in the target path using ":foo",  
equivalent to Erlang atom in WebMachine), or ":*" (only allowed at the  
end of a list, matches any number of tokens, can be captured in the  
target path using ":*", equivalent to Erlang atom '*' in WebMachine).

The target path is analogous to the match path, just that "atoms"  
specify parts of the match path to be captured.

Is this moving in the right direction?

It seems this can't cope with things like rewriting /blog/2009/05/08/ 
foo/ -> /db/blog%2F2009%2F05%2F08%2Ffoo though, or any other kind of  
slightly more flexible regex-style rewriting problems.  Any thoughts  
on this?

Thanks,
--
Jason Davies

www.jasondavies.com


Mime
View raw message