Hi,
I'd like to get some feedback on enhancing the _rewrite handler.
CouchDB would benefit from being able to handler this kind of rewrite:
{
"from": "/tags/:tagname",
"to": "_view/by-tag",
"query": { "key": ":tagname" }
}
Of course, you can do this with CouchDB 0.11, however you have to JSON
string encode the :tagname value in the URL, e.g.:
/tags/%22birthdays%22
When what I'd really like is:
/tags/birthdays
So I modified couch_httpd_rewrite.erl to JSON encode
key/startkey/endkey parameters, but I've hit a snag. Imagine you also
want to do the following:
{
"from": "/year/:year",
"to": "_view/by-year",
"query": { "key": ":year" }
}
This falls on its face (assuming that the by-year view emits numeric
keys) since the :year value would get JSON encoded to %222010%22 when
what you want is 2010. So, I suggest we come up a way to indicate when
a _rewrite query parameter should be treated as a JSON encoded string.
Here are two potential designs I could come up with:
{
"from": "/tags/:tagname",
"to": "_view/by-tag",
"query": {
"key": { "name": ":tagname", "json_encode": true }
}
}
Or:
{
"from": "/tags/:tagname",
"to": "_view/by-tag",
"query": {
"key": "\":tagname\""
}
}
A benefit to both these approaches would be that they maintain
backwards compatibility with the current behavior. Any better ideas?
Cheers,
Zach