couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benoit Chesneau <>
Subject couchdb rewrite handler
Date Sun, 24 Jan 2010 19:00:39 GMT

Folloging suggestion of @jchris I revisited my rewrite handler. This
time instead of using a javascript function to handle rewriting it
uses pattern matching in Erlang to do it. The rewriting root is the
the design doc :


ddocname should contain a "rewrites" member which a list of rewriting
rules. If not it will return a 404.

ex :

    "rewrite": [
            "from": "",
            "to": "index.html",
            "method": "GET",
            "query": {}

Urls are relatives to the db if they start by / or to the current path.

Rewriting can use variables. Variables in path are prefixed by ":".
For example the following rule:

{ "from": "show/:id", "to": "_show/mydoc/:id" }

will rewrite
          "/mydb/_design/test/_rewrite/show/someid" to

or { "from": "view/:type", "to": "_list/types/by_types", query: {
"key": "type" }
will rewrite :

          "/mydb/_design/test/_rewrite/view/sometype" to

So paths and query args can be rewrittend dynamically. The code is
currently in my github repo :
(couch_httpd_rewrite.erl) .

There is also some unitests :

Let me know what do you think about it.

- benoƮt

View raw message