Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 53246F038 for ; Wed, 20 Mar 2013 13:31:17 +0000 (UTC) Received: (qmail 40599 invoked by uid 500); 20 Mar 2013 13:31:14 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 40274 invoked by uid 500); 20 Mar 2013 13:31:13 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 40200 invoked by uid 99); 20 Mar 2013 13:31:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Mar 2013 13:31:11 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [66.111.4.25] (HELO out1-smtp.messagingengine.com) (66.111.4.25) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Mar 2013 13:31:06 +0000 Received: from compute4.internal (compute4.nyi.mail.srv.osa [10.202.2.44]) by gateway1.nyi.mail.srv.osa (Postfix) with ESMTP id B5D4921164; Wed, 20 Mar 2013 09:30:45 -0400 (EDT) Received: from frontend2.nyi.mail.srv.osa ([10.202.2.161]) by compute4.internal (MEProxy); Wed, 20 Mar 2013 09:30:45 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=message-id:date:from:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=T03pWfao2g+ssSD4Vu/0sd lK09k=; b=S+Fme9CFGGHQcwSxMrXYxc/Zsk6/NvExyKQbA4lDvtOSRM/yfyb3l4 Kk+QIyomdxnarfiX+puyPWnrFS3o/wBCcJuqfDw1YsMLIrx6KoCuLD1G0MZGylna xmOMYqBYXJ3YBIkdpgc7DDiIaQQb5Z2YsZeGqQdpRzd0rPeXCE1Ho= X-Sasl-enc: MzFVKLIUca8IBVwiwsLm38A0zQ1w56cuz9eVmgkUyWk7 1363786245 Received: from [192.168.10.8] (unknown [78.109.80.74]) by mail.messagingengine.com (Postfix) with ESMTPA id 2D55C20009F; Wed, 20 Mar 2013 09:30:45 -0400 (EDT) Message-ID: <5149BA03.4020603@berjon.com> Date: Wed, 20 Mar 2013 14:30:43 +0100 From: Robin Berjon User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130216 Thunderbird/17.0.3 MIME-Version: 1.0 To: user@couchdb.apache.org CC: Pulkit Singhal , couchdb-user@apache.org Subject: Re: How to workaround missing id in a request to Update Handler References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org Hi, 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: https://github.com/apache/couchdb/pull/38 -- Robin Berjon - http://berjon.com/ - @robinberjon