You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Pulkit Singhal <pu...@gmail.com> on 2013/03/19 20:57:13 UTC

How to workaround missing id in a request to Update Handler

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.

Thoughts?

Re: How to workaround missing id in a request to Update Handler

Posted by Dave Cottlehuber <dc...@jsonified.com>.
On 20 March 2013 15:01, Benoit Chesneau <bc...@gmail.com> wrote:
> Here is a simple router example:
>
> https://github.com/benoitc/couchapp-ng/blob/master/example/legacyapp/routes.json

So we're all +1 on having a better rewriter in some form. Great!

Have any of the nodejs people here ever considered using a node-based
router that is locked into couchdb via the externals API?
http://docs.couchdb.org/en/latest/os-daemons.html and
http://davispj.com/2010/09/26/new-couchdb-externals-api.html

A+
Dave

Re: How to workaround missing id in a request to Update Handler

Posted by Benoit Chesneau <bc...@gmail.com>.
On Wed, Mar 20, 2013 at 6:59 AM, Benoit Chesneau <bc...@gmail.com> wrote:
> On Wed, Mar 20, 2013 at 6:43 AM, Robert Newson <rn...@apache.org> wrote:
>> Hi Robin,
>>
>> I re-read the comments on your PR. I hope you didn't read it too
>> personally as I'm sure that wasn't the intention of those that
>> commented. The issue is that a roundtrip through Javascript evaluation
>> is a significaters arnt overhead. No matter how you implemented it, it would
>> almost certainly be too slow for a useful URL rewriting feature. I
>> don't dispute that the URL rewriter in couchdb could be improved,
>> though. I think a viable path would be a more powerful microlanguage,
>> something modelled on mod_rewrite or the nginx module, perhaps? In
>> summary, I'd love to see a rewriter feature in CouchDB that is
>> comprehensive while still being fast; you're not the first to reach
>> its limits.
>>
>> B.
>>
>>
>
> One less limited I proposed 2 years ago is that one too:
>
> https://github.com/benoitc/couchapp-ng
>
> Which is not reusing another dsl but simply the regexp pattern like
> all routers around. But what is really wanted here is a full access to
> the couchdb api to return a doc from anything in the query or headers.
> which is quite different. We could also go for another script language
> like lua that can be interpreted natively.
>
> - benoit

Here is a simple router example:

https://github.com/benoitc/couchapp-ng/blob/master/example/legacyapp/routes.json

Re: How to workaround missing id in a request to Update Handler

Posted by Benoit Chesneau <bc...@gmail.com>.
On Wed, Mar 20, 2013 at 6:43 AM, Robert Newson <rn...@apache.org> wrote:
> Hi Robin,
>
> I re-read the comments on your PR. I hope you didn't read it too
> personally as I'm sure that wasn't the intention of those that
> commented. The issue is that a roundtrip through Javascript evaluation
> is a significaters arnt overhead. No matter how you implemented it, it would
> almost certainly be too slow for a useful URL rewriting feature. I
> don't dispute that the URL rewriter in couchdb could be improved,
> though. I think a viable path would be a more powerful microlanguage,
> something modelled on mod_rewrite or the nginx module, perhaps? In
> summary, I'd love to see a rewriter feature in CouchDB that is
> comprehensive while still being fast; you're not the first to reach
> its limits.
>
> B.
>
>

One less limited I proposed 2 years ago is that one too:

https://github.com/benoitc/couchapp-ng

Which is not reusing another dsl but simply the regexp pattern like
all routers around. But what is really wanted here is a full access to
the couchdb api to return a doc from anything in the query or headers.
which is quite different. We could also go for another script language
like lua that can be interpreted natively.

- benoit

Re: How to workaround missing id in a request to Update Handler

Posted by Robert Newson <rn...@apache.org>.
Hi Robin,

I re-read the comments on your PR. I hope you didn't read it too
personally as I'm sure that wasn't the intention of those that
commented. The issue is that a roundtrip through Javascript evaluation
is a significant overhead. No matter how you implemented it, it would
almost certainly be too slow for a useful URL rewriting feature. I
don't dispute that the URL rewriter in couchdb could be improved,
though. I think a viable path would be a more powerful microlanguage,
something modelled on mod_rewrite or the nginx module, perhaps? In
summary, I'd love to see a rewriter feature in CouchDB that is
comprehensive while still being fast; you're not the first to reach
its limits.

B.

On 20 March 2013 13:30, Robin Berjon <ro...@berjon.com> wrote:
> 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

Re: How to workaround missing id in a request to Update Handler

Posted by Robin Berjon <ro...@berjon.com>.
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