As the OP stated, there's no way to get the rewriter to automatically
string those values without using an array for the key.
Note that the example from the unit tests only does numbers:
xhr = CouchDB.request("GET",
"/test_suite_db/_design/test/_rewrite/simpleForm/basicViewPath/3/8");
But if you tried:
/test_suite_db/_design/test/_rewrite/simpleForm/basicViewPath/foo/bar
Couch would complain because the key values (foo and bar) aren't valid
JSON (which is needed for view query keys) without being enclosed in
quotes.
Of course, this would work:
/test_suite_db/_design/test/_rewrite/simpleForm/basicViewPath/%22foo%22/%22bar%22
But the whole point of URL rewriting to is provide nice URLs.
On Tue, Sep 7, 2010 at 4:35 PM, Benoit Chesneau <[email protected]> wrote:
> On Tue, Sep 7, 2010 at 11:13 AM, Taras Puchko <[email protected]> wrote:
>> The docs [1] state that the key must be a proper URL encoded JSON value,
>> so _view/by-tag?key=java won't work, but _view/by-tag?key="java" will.
>>
>> [1] http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
>>
>> Cheers,
>> Taras
>>
>>
>> On Tue, Sep 7, 2010 at 8:18 PM, Benoit Chesneau <[email protected]> wrote:
>>>
>>> On Tue, Sep 7, 2010 at 5:56 AM, Taras Puchko <[email protected]> wrote:
>>> > Hello,
>>> >
>>> > I'm trying to use a URL segment as a key for a view, like the following:
>>> > {
>>> > "from": "/tags/:tagname",
>>> > "to": "_view/by-tag",
>>> > "query": {"key": ":tagname"}
>>> > }
>>> >
>>> > The problem is that the key have to be JSON-encoded, which complicates my
>>> > API. Every client has to know how to JSON-encode strings.
>>> >
>>> > However, I have found a workaround. If I use arrays for my keys the
>>> > following works:
>>> > {
>>> > "from": "/tags/:tagname",
>>> > "to": "_view/by-tag",
>>> > "query": {"key": [":tagname"]}
>>> > }
>>> >
>>> > I'm wondering if there is a more efficient solution for this problem.
>>> >
>>> > Thanks,
>>> > Taras
>>> >
>>>
>>> The key doesn't need to be json encoded only url encoded. If not let me
>>> know.
>>>
>>> - benoit
>>
>
> i mean as a param. If you use ":tagname "it should work. Ex from unit tests :
>
> {
> "from": "simpleForm/basicViewPath/:start/:end",
> "to": "_list/simpleForm/basicView",
> "query": {
> "startkey": ":start",
> "endkey": ":end"
> }
> },
>