couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robin Berjon <>
Subject Re: How to workaround missing id in a request to Update Handler
Date Wed, 20 Mar 2013 13:30:43 GMT

On 19/03/2013 20:57 , Pulkit Singhal wrote:
> 1) I have a 3rd-party-webhook API calling into my update handler and
> there's nothing I can do to make it pass the document ID in the URL.
> 2) That means the CouchDB server cannot provide the update function with
> the most recent version of that document.
> 3) But the request does provide a payload from which I can pull out the
> document ID ... but by this time I'm inside the update handler function.
> 4) So my question is: If CouchDB did not provide a doc, is there still a
> way for me to:
> a) either, fetch the latest version of the doc myself?
> b) or, override the existing document with another document formed with my
> request payload ... without running into a revision conflict?
> I know that I can probably route the request through a proxy that parses
> the payload, sets the document ID onto the request URL and sends it own its
> way ... but I'd rather leave that as a last resort.

I had a similar problem trying to get a CouchApp to support nice URLs 
with nice-looking IDs. Sadly, I couldn't get it to work for my case, but 
there may be a solution for you depending on how the third party that's 
contacting you is working. *If* it follows redirects, then when you get 
a request without an ID you can extract it from the payload and issue a 
redirect to the URL with the ID. This doesn't work reliably with 
browsers (which is why I couldn't use it) but the odds are it might work 
for you.

I had also worked on a patch that made Couch's rewrite system more 
powerful in order to handle precisely this case (since right now you 
simply can't both have nice URLs and be properly RESTful with Couch), 
but it wasn't very popular. If you have the time and energy to address 
the problems that people had with it, you can find it at:

Robin Berjon - - @robinberjon

View raw message