couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: API suggestions
Date Thu, 04 Dec 2008 21:40:51 GMT
On Thu, Dec 4, 2008 at 10:45 AM, Dean Landolt <> wrote:

> >
> > I remember some discussion
> > about rewrite rules on the roadmap

> I'm not sure I'd go so far as to say they are on the roadmap.
> Currently
you can exercise a lot of control with the .ini files, and I
> think that
will continue to become more flexible. Implementing Django
> or Rails style
routing for CouchDB is most likely *not* on the
> roadmap. It would wreck
havoc on client libraries.
> However, with _external mounted at a high
point in the path, maybe
> /_route/blah/blah could let you parse routes in
javascript, and make
> additional http requests to satisfy them.
> I
know this integration isn't very tight, but it's an ideal lab to see
> what
people come up with. Porting from JS to Erlang isn't hard, so
> prototyping
new API features with _external seems like an easy way to
> proceed.


I'm been playing with CouchDB for the last couple of weeks with the
intention of making a self-contained 'app-engine' serving applications out
of the database (apps as design documents).

I now have a working prototype
(yay!), and custom routing was one of the few things I've had to patch in
order to implement my own app-based dispatching.

My patch, below, basically
allows for an optional '_' entry in global and db handlers to specify some
other non-default handlers to be used when no other matching handlers are
found. It can obviously be used for other purposes, for instance writing handlers
that simply do pre- and post-processing for specific purposes on top of the
default handlers.

The patch makes it a 'hidden' feature, but I don't see
why explicit '_' entries shouldn't be part of default config (pointing to
the current default handlers).



--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
-138,7 +138,8 @@
                 || Part <- string:tokens(Path, "/")],
         db_url_handlers = DbUrlHandlers
-    DefaultFun = fun
+    DefaultFun = couch_util:dict_find(<<"_">>,
+                                        fun couch_httpd_db:handle_request/1),

     HandlerFun = couch_util:dict_find(HandlerKey, UrlHandlers, DefaultFun),

     {ok, Resp} =
--- a/src/couchdb/couch_httpd_db.erl

+++ b/src/couchdb/couch_httpd_db.erl
@@ -37,7 +37,10 @@
     {_, []} ->

         do_db_req(Req, fun db_req/2);
     {_, [SecondPart|_]} ->
     Handler = couch_util:dict_find(SecondPart, DbUrlHandlers, fun db_req/2),

+        DefaultHandler = couch_util:dict_find(<<"_">>, DbUrlHandlers,
                                   fun db_req/2),
+        Handler = couch_util:dict_find(SecondPart,
+                                    DefaultHandler),
      do_db_req(Req, Handler)

View raw message