You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Chris Anderson (JIRA)" <ji...@apache.org> on 2009/03/04 05:15:56 UTC
[jira] Created: (COUCHDB-280) relative links between resources
provided by design docs
relative links between resources provided by design docs
--------------------------------------------------------
Key: COUCHDB-280
URL: https://issues.apache.org/jira/browse/COUCHDB-280
Project: CouchDB
Issue Type: Improvement
Reporter: Chris Anderson
Assignee: Chris Anderson
Fix For: 0.9
In an earlier thread we discussed the costs and benefits of changing CouchDB so that all the resources provided by a design doc are rooted in the design doc.
Under the current system, there is no way to link among HTML files attached to a design docs, the HTML output of show and list functions, and view queries. The only way to link between these resources is by hard-coding the design doc name in your link. By giving the resources provided by design docs a common root, one can link between them using hrefs like "../../_show/sname/docid".
The current system never posed a problem before, because design docs only provided one type of resource. However, going forward I can see that design docs could continue to provide new, unanticipated resources. Jason Davies has proposed an _update resource, which would be a JavaScript (or other language) function that can accept request with non-JSON bodies (for instance POSTed XML from a webhook service) and convert them to JSON for storage.
The advantages to decomposing the traditional "accept a request, do whatever you want, send a reply" app-server model into discrete functions are numerous, the main one being that developers can support custom non-JSON content-types, while still interacting with the database in a manner where side-effects and memory / runtime characteristics are controlled.
Show and list break non-JSON rendering down into the right sized granules for safe, cacheable idempotent requests. But because we we can't link between them (and design doc attachments) using normal html links (the links must be computed on the server) they aren't enough to provide a hypermedia interface for CouchDB. Hypermedia is above what CouchDB has been shooting for, but we are so close now that it seems silly not to go the "rest" of the way.
If it were just the tradeoffs between relative links (good) and slightly uglier urls (bad) I'd be roughly +0 on this change. But a consequence of giving design doc resources a common root is that the applications the define can then be proxied with a URL rewriter. The means that (if written correctly) an application with paths like:
/db/_design/foo/_view/bar?limit=10
/db/_design/foo/_show/docid
/db/_design/foo/index.html
can be proxied so that the "/db/_design/foo" part of the URL is added by the proxy, so that all clients see is:
/_view/bar?limit=10
/_show/docid
/index.html
This also nicely limits end-client access, so that they may only interact with the database using resources provided by the design doc. I consider this an edge-case for deployment but the fact that we can cleanly support makes me think we're on the right track with the change to a common root for design doc resources.
For more details about these URL path interactions, see the earlier thread:
http://mail-archives.apache.org/mod_mbox/couchdb-dev/200902.mbox/%3Ce282921e0902242116n2cd207c4x7a9d0feced3f10d9@mail.gmail.com%3E
I've implemented a patch (attached to this ticket) that makes it so that views, shows, lists, and design doc attachments are all rooted under the design doc.
It works by adding a section to the ini file, like this (which we could use to easily add new resource, like the _update mentioned above):
[httpd_design_handlers]
_view = {couch_httpd_view, handle_view_req}
_show = {couch_httpd_show, handle_doc_show_req}
_list = {couch_httpd_show, handle_view_list_req}
the _design handler itself is just an http_db_handler.
Points of discussion:
If we want to change the names of any of: _view, _show, _list, or _design now is a good time to do it. We've been over the names _list and _show many times, and while they aren't perfect, they are short, and more-or-less descriptive of what they do.
The code is robust about changes to the _design db handler's name. That is, we could continue to call them design docs, and store them with ids like "_design/name", while changing the resource root so that the above set of URLs could be something like (modulo an attachments handler, "_files" here, for clarity):
/db/_baz/foo/_view/bar?limit=10
/db/_baz/foo/_show/docid
/db/_baz/foo/_files/index.html
Before we commit / before 0.9.0:
This patch is a big enough change that I think we should vote on it before I commit it. However, I'd like to get it in before 0.9.0 to avoid future confusion where trunk is incompatible with API clients and applications designed to run on our latest release.
Sincerely,
Chris
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
Re: [jira] Created: (COUCHDB-280) relative links between resources
provided by design docs
Posted by Dean Landolt <de...@deanlandolt.com>.
On Wed, Mar 4, 2009 at 12:15 PM, Jason Davies <ja...@jasondavies.com> wrote:
> - Show quoted text -
>
> On 4 Mar 2009, at 16:57, Chris Anderson wrote:
>
> On Wed, Mar 4, 2009 at 8:43 AM, Chris Anderson <jc...@apache.org> wrote:
>>
>>> On Wed, Mar 4, 2009 at 8:34 AM, Jason Davies <ja...@jasondavies.com>
>>> wrote:
>>>
>>>> I also prefer _render. How about doing the analogous to what we do for
>>>> JSON
>>>> docs and views, i.e. something like:
>>>>
>>>> /db/_design/foo/_render/renderfun/docid
>>>> /db/_design/foo/_render/renderfun/_view/viewname
>>>>
>>>>
>>> I do believe this works, but I'm not convinced it is more elegant that
>>> having one name for rendering views and one name for rendering
>>> documents. For one thing, it doesn't take advantage of the
>>> [httpd_design_handlers] extension point, and for another, it's just
>>> plain long!
>>
>>
I think the [httpd_design_handlers] layout is far more elegant than
_list/_show is ugly.
>
>>>
>>> Not totally against it, but to me it's like making an origami
>>> paper-crane, and then adding an elephant leg to it.
>>>
>>>
>> That said, let me be clear that I'm flexible and if a consensus
>> emerges that something that doesn't fit the httpd_design_handlers
>> extension point is preferred, I'm happy to help change it to that.
>>
>> Another disadvantage to the deeper URLs required by stacking the doc
>> and view rendering namespaces is that links from rendered views to
>> rendered docs start to look like "../../../docrenderfun/docid"
>>
>
> Good points. I must say, having worked with the _list and _show names for
> a while now, I don't think they're terrible and personally I've just got
> used to them. They're actually slightly similar to Django's list_detail
> generic views, which are called "object_list" and "object_detail". Any
> other naming ideas from other projects? We could change _show to _detail
> but that's an extra 2 characters (!) and I don't think it's any better
> really.
Great example. I couldn't agree more.
+1 to httpd_design_handlers, +1 to _list, +0 to show (until something better
emerges).
Re: [jira] Created: (COUCHDB-280) relative links between resources provided by design docs
Posted by Jason Davies <ja...@jasondavies.com>.
On 4 Mar 2009, at 16:57, Chris Anderson wrote:
> On Wed, Mar 4, 2009 at 8:43 AM, Chris Anderson <jc...@apache.org>
> wrote:
>> On Wed, Mar 4, 2009 at 8:34 AM, Jason Davies
>> <ja...@jasondavies.com> wrote:
>>> I also prefer _render. How about doing the analogous to what we
>>> do for JSON
>>> docs and views, i.e. something like:
>>>
>>> /db/_design/foo/_render/renderfun/docid
>>> /db/_design/foo/_render/renderfun/_view/viewname
>>>
>>
>> I do believe this works, but I'm not convinced it is more elegant
>> that
>> having one name for rendering views and one name for rendering
>> documents. For one thing, it doesn't take advantage of the
>> [httpd_design_handlers] extension point, and for another, it's just
>> plain long!
>>
>> Not totally against it, but to me it's like making an origami
>> paper-crane, and then adding an elephant leg to it.
>>
>
> That said, let me be clear that I'm flexible and if a consensus
> emerges that something that doesn't fit the httpd_design_handlers
> extension point is preferred, I'm happy to help change it to that.
>
> Another disadvantage to the deeper URLs required by stacking the doc
> and view rendering namespaces is that links from rendered views to
> rendered docs start to look like "../../../docrenderfun/docid"
Good points. I must say, having worked with the _list and _show names
for a while now, I don't think they're terrible and personally I've
just got used to them. They're actually slightly similar to Django's
list_detail generic views, which are called "object_list" and
"object_detail". Any other naming ideas from other projects? We
could change _show to _detail but that's an extra 2 characters (!) and
I don't think it's any better really.
--
Jason Davies
www.jasondavies.com
Re: [jira] Created: (COUCHDB-280) relative links between resources
provided by design docs
Posted by Chris Anderson <jc...@apache.org>.
On Wed, Mar 4, 2009 at 8:43 AM, Chris Anderson <jc...@apache.org> wrote:
> On Wed, Mar 4, 2009 at 8:34 AM, Jason Davies <ja...@jasondavies.com> wrote:
>> I also prefer _render. How about doing the analogous to what we do for JSON
>> docs and views, i.e. something like:
>>
>> /db/_design/foo/_render/renderfun/docid
>> /db/_design/foo/_render/renderfun/_view/viewname
>>
>
> I do believe this works, but I'm not convinced it is more elegant that
> having one name for rendering views and one name for rendering
> documents. For one thing, it doesn't take advantage of the
> [httpd_design_handlers] extension point, and for another, it's just
> plain long!
>
> Not totally against it, but to me it's like making an origami
> paper-crane, and then adding an elephant leg to it.
>
That said, let me be clear that I'm flexible and if a consensus
emerges that something that doesn't fit the httpd_design_handlers
extension point is preferred, I'm happy to help change it to that.
Another disadvantage to the deeper URLs required by stacking the doc
and view rendering namespaces is that links from rendered views to
rendered docs start to look like "../../../docrenderfun/docid"
Chris
--
Chris Anderson
http://jchris.mfdz.com
Re: [jira] Created: (COUCHDB-280) relative links between resources
provided by design docs
Posted by Chris Anderson <jc...@apache.org>.
On Wed, Mar 4, 2009 at 8:34 AM, Jason Davies <ja...@jasondavies.com> wrote:
> I also prefer _render. How about doing the analogous to what we do for JSON
> docs and views, i.e. something like:
>
> /db/_design/foo/_render/renderfun/docid
> /db/_design/foo/_render/renderfun/_view/viewname
>
I do believe this works, but I'm not convinced it is more elegant that
having one name for rendering views and one name for rendering
documents. For one thing, it doesn't take advantage of the
[httpd_design_handlers] extension point, and for another, it's just
plain long!
Not totally against it, but to me it's like making an origami
paper-crane, and then adding an elephant leg to it.
--
Chris Anderson
http://jchris.mfdz.com
Re: [jira] Created: (COUCHDB-280) relative links between resources provided by design docs
Posted by Jason Davies <ja...@jasondavies.com>.
On 4 Mar 2009, at 16:16, Jan Lehnardt wrote:
> On 4 Mar 2009, at 05:15, Chris Anderson (JIRA) wrote:
>
>> Points of discussion:
>>
>> If we want to change the names of any of: _view, _show, _list, or
>> _design now is a good time to do it. We've been over the names
>> _list and _show many times, and while they aren't perfect, they are
>> short, and more-or-less descriptive of what they do.
>
> I'd still love to see _render/ used for both docs and views.
>
> /db/_design/foo/_render/renderfun/docid
> /db/_design/foo/_render/renderfun/viewname
>
> The problem with this of course is that the docid namespace gets
> polluted with viewnames (or vice versa) and 404-handling will prove
> to be tricky. _-prefixing viewnames would be one option, but then
> you can't have views named "design", heh :)
>
> /db/_design/foo/_render/renderfun/docid
> /db/_design/foo/_render/renderfun/_viewname
I also prefer _render. How about doing the analogous to what we do
for JSON docs and views, i.e. something like:
/db/_design/foo/_render/renderfun/docid
/db/_design/foo/_render/renderfun/_view/viewname
This would work at the moment because slashes in the docid URL are URL-
encoded, i.e. in the (unlikely) event of a doc with an id of "_view/
viewname", it would be rendered via _render/renderfun/_view
%2Fviewname, hence no collisions. Even if we were to allow unescaped
slashes in the docid URL e.g. _render/renderfun/foo/bar/baz/ where the
docid is "foo/bar/baz/", we still maintain _* as a reserved namespace
so there's no danger of anyone creating a document with docid "_view/
*", hence I think is pretty future-proof in that sense.
>
>
> Another possibility would be requiring prefixes for render functions:
>
> /db/_design/foo/_render/doc-renderfun/docid
> /db/_design/foo/_render/view-renderfun/viewname
>
> not neat, but better than _list and _show.
>
> The new URL layout might enable other solutions that I don't see yet.
>
>
>
>> The code is robust about changes to the _design db handler's name.
>> That is, we could continue to call them design docs, and store them
>> with ids like "_design/name", while changing the resource root so
>> that the above set of URLs could be something like (modulo an
>> attachments handler, "_files" here, for clarity):
>>
>> /db/_baz/foo/_view/bar?limit=10
>> /db/_baz/foo/_show/docid
>> /db/_baz/foo/_files/index.html
>>
>> Before we commit / before 0.9.0:
>>
>> This patch is a big enough change that I think we should vote on it
>> before I commit it. However, I'd like to get it in before 0.9.0 to
>> avoid future confusion where trunk is incompatible with API clients
>> and applications designed to run on our latest release.
>
> +1 (for the general idea of the patch after refining the API).
+1 FWIW :-)
--
Jason Davies
www.jasondavies.com
Re: [jira] Created: (COUCHDB-280) relative links between resources provided by design docs
Posted by Jan Lehnardt <ja...@apache.org>.
On 4 Mar 2009, at 05:15, Chris Anderson (JIRA) wrote:
> Points of discussion:
>
> If we want to change the names of any of: _view, _show, _list, or
> _design now is a good time to do it. We've been over the names _list
> and _show many times, and while they aren't perfect, they are short,
> and more-or-less descriptive of what they do.
I'd still love to see _render/ used for both docs and views.
/db/_design/foo/_render/renderfun/docid
/db/_design/foo/_render/renderfun/viewname
The problem with this of course is that the docid namespace gets
polluted with viewnames (or vice versa) and 404-handling will prove to
be tricky. _-prefixing viewnames would be one option, but then you
can't have views named "design", heh :)
/db/_design/foo/_render/renderfun/docid
/db/_design/foo/_render/renderfun/_viewname
Another possibility would be requiring prefixes for render functions:
/db/_design/foo/_render/doc-renderfun/docid
/db/_design/foo/_render/view-renderfun/viewname
not neat, but better than _list and _show.
The new URL layout might enable other solutions that I don't see yet.
> The code is robust about changes to the _design db handler's name.
> That is, we could continue to call them design docs, and store them
> with ids like "_design/name", while changing the resource root so
> that the above set of URLs could be something like (modulo an
> attachments handler, "_files" here, for clarity):
>
> /db/_baz/foo/_view/bar?limit=10
> /db/_baz/foo/_show/docid
> /db/_baz/foo/_files/index.html
>
> Before we commit / before 0.9.0:
>
> This patch is a big enough change that I think we should vote on it
> before I commit it. However, I'd like to get it in before 0.9.0 to
> avoid future confusion where trunk is incompatible with API clients
> and applications designed to run on our latest release.
+1 (for the general idea of the patch after refining the API).
Cheers
Jan
--
[jira] Updated: (COUCHDB-280) relative links between resources
provided by design docs
Posted by "Chris Anderson (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/COUCHDB-280?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Chris Anderson updated COUCHDB-280:
-----------------------------------
Attachment: relative-design-paths.diff
Here is a patch, against r749902.
The previously mentioned github branch is out of date. If you want to use git, the branch is here:
http://github.com/jchris/couchdb/tree/rel-paths-rebased
> relative links between resources provided by design docs
> --------------------------------------------------------
>
> Key: COUCHDB-280
> URL: https://issues.apache.org/jira/browse/COUCHDB-280
> Project: CouchDB
> Issue Type: Improvement
> Reporter: Chris Anderson
> Assignee: Chris Anderson
> Fix For: 0.9
>
> Attachments: relative-design-paths.diff
>
>
> In an earlier thread we discussed the costs and benefits of changing CouchDB so that all the resources provided by a design doc are rooted in the design doc.
> Under the current system, there is no way to link among HTML files attached to a design docs, the HTML output of show and list functions, and view queries. The only way to link between these resources is by hard-coding the design doc name in your link. By giving the resources provided by design docs a common root, one can link between them using hrefs like "../../_show/sname/docid".
> The current system never posed a problem before, because design docs only provided one type of resource. However, going forward I can see that design docs could continue to provide new, unanticipated resources. Jason Davies has proposed an _update resource, which would be a JavaScript (or other language) function that can accept request with non-JSON bodies (for instance POSTed XML from a webhook service) and convert them to JSON for storage.
> The advantages to decomposing the traditional "accept a request, do whatever you want, send a reply" app-server model into discrete functions are numerous, the main one being that developers can support custom non-JSON content-types, while still interacting with the database in a manner where side-effects and memory / runtime characteristics are controlled.
> Show and list break non-JSON rendering down into the right sized granules for safe, cacheable idempotent requests. But because we we can't link between them (and design doc attachments) using normal html links (the links must be computed on the server) they aren't enough to provide a hypermedia interface for CouchDB. Hypermedia is above what CouchDB has been shooting for, but we are so close now that it seems silly not to go the "rest" of the way.
> If it were just the tradeoffs between relative links (good) and slightly uglier urls (bad) I'd be roughly +0 on this change. But a consequence of giving design doc resources a common root is that the applications the define can then be proxied with a URL rewriter. The means that (if written correctly) an application with paths like:
> /db/_design/foo/_view/bar?limit=10
> /db/_design/foo/_show/docid
> /db/_design/foo/index.html
> can be proxied so that the "/db/_design/foo" part of the URL is added by the proxy, so that all clients see is:
> /_view/bar?limit=10
> /_show/docid
> /index.html
> This also nicely limits end-client access, so that they may only interact with the database using resources provided by the design doc. I consider this an edge-case for deployment but the fact that we can cleanly support makes me think we're on the right track with the change to a common root for design doc resources.
> For more details about these URL path interactions, see the earlier thread:
> http://mail-archives.apache.org/mod_mbox/couchdb-dev/200902.mbox/%3Ce282921e0902242116n2cd207c4x7a9d0feced3f10d9@mail.gmail.com%3E
> I've implemented a patch (attached to this ticket) that makes it so that views, shows, lists, and design doc attachments are all rooted under the design doc.
> It works by adding a section to the ini file, like this (which we could use to easily add new resource, like the _update mentioned above):
> [httpd_design_handlers]
> _view = {couch_httpd_view, handle_view_req}
> _show = {couch_httpd_show, handle_doc_show_req}
> _list = {couch_httpd_show, handle_view_list_req}
> the _design handler itself is just an http_db_handler.
> Points of discussion:
> If we want to change the names of any of: _view, _show, _list, or _design now is a good time to do it. We've been over the names _list and _show many times, and while they aren't perfect, they are short, and more-or-less descriptive of what they do.
> The code is robust about changes to the _design db handler's name. That is, we could continue to call them design docs, and store them with ids like "_design/name", while changing the resource root so that the above set of URLs could be something like (modulo an attachments handler, "_files" here, for clarity):
> /db/_baz/foo/_view/bar?limit=10
> /db/_baz/foo/_show/docid
> /db/_baz/foo/_files/index.html
> Before we commit / before 0.9.0:
> This patch is a big enough change that I think we should vote on it before I commit it. However, I'd like to get it in before 0.9.0 to avoid future confusion where trunk is incompatible with API clients and applications designed to run on our latest release.
> Sincerely,
> Chris
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Closed: (COUCHDB-280) relative links between resources
provided by design docs
Posted by "Chris Anderson (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/COUCHDB-280?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Chris Anderson closed COUCHDB-280.
----------------------------------
Resolution: Fixed
closed in r751813
> relative links between resources provided by design docs
> --------------------------------------------------------
>
> Key: COUCHDB-280
> URL: https://issues.apache.org/jira/browse/COUCHDB-280
> Project: CouchDB
> Issue Type: Improvement
> Reporter: Chris Anderson
> Assignee: Chris Anderson
> Fix For: 0.9
>
> Attachments: relative-design-paths.diff
>
>
> In an earlier thread we discussed the costs and benefits of changing CouchDB so that all the resources provided by a design doc are rooted in the design doc.
> Under the current system, there is no way to link among HTML files attached to a design docs, the HTML output of show and list functions, and view queries. The only way to link between these resources is by hard-coding the design doc name in your link. By giving the resources provided by design docs a common root, one can link between them using hrefs like "../../_show/sname/docid".
> The current system never posed a problem before, because design docs only provided one type of resource. However, going forward I can see that design docs could continue to provide new, unanticipated resources. Jason Davies has proposed an _update resource, which would be a JavaScript (or other language) function that can accept request with non-JSON bodies (for instance POSTed XML from a webhook service) and convert them to JSON for storage.
> The advantages to decomposing the traditional "accept a request, do whatever you want, send a reply" app-server model into discrete functions are numerous, the main one being that developers can support custom non-JSON content-types, while still interacting with the database in a manner where side-effects and memory / runtime characteristics are controlled.
> Show and list break non-JSON rendering down into the right sized granules for safe, cacheable idempotent requests. But because we we can't link between them (and design doc attachments) using normal html links (the links must be computed on the server) they aren't enough to provide a hypermedia interface for CouchDB. Hypermedia is above what CouchDB has been shooting for, but we are so close now that it seems silly not to go the "rest" of the way.
> If it were just the tradeoffs between relative links (good) and slightly uglier urls (bad) I'd be roughly +0 on this change. But a consequence of giving design doc resources a common root is that the applications the define can then be proxied with a URL rewriter. The means that (if written correctly) an application with paths like:
> /db/_design/foo/_view/bar?limit=10
> /db/_design/foo/_show/docid
> /db/_design/foo/index.html
> can be proxied so that the "/db/_design/foo" part of the URL is added by the proxy, so that all clients see is:
> /_view/bar?limit=10
> /_show/docid
> /index.html
> This also nicely limits end-client access, so that they may only interact with the database using resources provided by the design doc. I consider this an edge-case for deployment but the fact that we can cleanly support makes me think we're on the right track with the change to a common root for design doc resources.
> For more details about these URL path interactions, see the earlier thread:
> http://mail-archives.apache.org/mod_mbox/couchdb-dev/200902.mbox/%3Ce282921e0902242116n2cd207c4x7a9d0feced3f10d9@mail.gmail.com%3E
> I've implemented a patch (attached to this ticket) that makes it so that views, shows, lists, and design doc attachments are all rooted under the design doc.
> It works by adding a section to the ini file, like this (which we could use to easily add new resource, like the _update mentioned above):
> [httpd_design_handlers]
> _view = {couch_httpd_view, handle_view_req}
> _show = {couch_httpd_show, handle_doc_show_req}
> _list = {couch_httpd_show, handle_view_list_req}
> the _design handler itself is just an http_db_handler.
> Points of discussion:
> If we want to change the names of any of: _view, _show, _list, or _design now is a good time to do it. We've been over the names _list and _show many times, and while they aren't perfect, they are short, and more-or-less descriptive of what they do.
> The code is robust about changes to the _design db handler's name. That is, we could continue to call them design docs, and store them with ids like "_design/name", while changing the resource root so that the above set of URLs could be something like (modulo an attachments handler, "_files" here, for clarity):
> /db/_baz/foo/_view/bar?limit=10
> /db/_baz/foo/_show/docid
> /db/_baz/foo/_files/index.html
> Before we commit / before 0.9.0:
> This patch is a big enough change that I think we should vote on it before I commit it. However, I'd like to get it in before 0.9.0 to avoid future confusion where trunk is incompatible with API clients and applications designed to run on our latest release.
> Sincerely,
> Chris
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
[jira] Commented: (COUCHDB-280) relative links between resources
provided by design docs
Posted by "Chris Anderson (JIRA)" <ji...@apache.org>.
[ https://issues.apache.org/jira/browse/COUCHDB-280?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12678577#action_12678577 ]
Chris Anderson commented on COUCHDB-280:
----------------------------------------
Patch forthcoming, you can access it here while I rebase against trunk:
http://github.com/jchris/couchdb/tree/rel-paths
> relative links between resources provided by design docs
> --------------------------------------------------------
>
> Key: COUCHDB-280
> URL: https://issues.apache.org/jira/browse/COUCHDB-280
> Project: CouchDB
> Issue Type: Improvement
> Reporter: Chris Anderson
> Assignee: Chris Anderson
> Fix For: 0.9
>
>
> In an earlier thread we discussed the costs and benefits of changing CouchDB so that all the resources provided by a design doc are rooted in the design doc.
> Under the current system, there is no way to link among HTML files attached to a design docs, the HTML output of show and list functions, and view queries. The only way to link between these resources is by hard-coding the design doc name in your link. By giving the resources provided by design docs a common root, one can link between them using hrefs like "../../_show/sname/docid".
> The current system never posed a problem before, because design docs only provided one type of resource. However, going forward I can see that design docs could continue to provide new, unanticipated resources. Jason Davies has proposed an _update resource, which would be a JavaScript (or other language) function that can accept request with non-JSON bodies (for instance POSTed XML from a webhook service) and convert them to JSON for storage.
> The advantages to decomposing the traditional "accept a request, do whatever you want, send a reply" app-server model into discrete functions are numerous, the main one being that developers can support custom non-JSON content-types, while still interacting with the database in a manner where side-effects and memory / runtime characteristics are controlled.
> Show and list break non-JSON rendering down into the right sized granules for safe, cacheable idempotent requests. But because we we can't link between them (and design doc attachments) using normal html links (the links must be computed on the server) they aren't enough to provide a hypermedia interface for CouchDB. Hypermedia is above what CouchDB has been shooting for, but we are so close now that it seems silly not to go the "rest" of the way.
> If it were just the tradeoffs between relative links (good) and slightly uglier urls (bad) I'd be roughly +0 on this change. But a consequence of giving design doc resources a common root is that the applications the define can then be proxied with a URL rewriter. The means that (if written correctly) an application with paths like:
> /db/_design/foo/_view/bar?limit=10
> /db/_design/foo/_show/docid
> /db/_design/foo/index.html
> can be proxied so that the "/db/_design/foo" part of the URL is added by the proxy, so that all clients see is:
> /_view/bar?limit=10
> /_show/docid
> /index.html
> This also nicely limits end-client access, so that they may only interact with the database using resources provided by the design doc. I consider this an edge-case for deployment but the fact that we can cleanly support makes me think we're on the right track with the change to a common root for design doc resources.
> For more details about these URL path interactions, see the earlier thread:
> http://mail-archives.apache.org/mod_mbox/couchdb-dev/200902.mbox/%3Ce282921e0902242116n2cd207c4x7a9d0feced3f10d9@mail.gmail.com%3E
> I've implemented a patch (attached to this ticket) that makes it so that views, shows, lists, and design doc attachments are all rooted under the design doc.
> It works by adding a section to the ini file, like this (which we could use to easily add new resource, like the _update mentioned above):
> [httpd_design_handlers]
> _view = {couch_httpd_view, handle_view_req}
> _show = {couch_httpd_show, handle_doc_show_req}
> _list = {couch_httpd_show, handle_view_list_req}
> the _design handler itself is just an http_db_handler.
> Points of discussion:
> If we want to change the names of any of: _view, _show, _list, or _design now is a good time to do it. We've been over the names _list and _show many times, and while they aren't perfect, they are short, and more-or-less descriptive of what they do.
> The code is robust about changes to the _design db handler's name. That is, we could continue to call them design docs, and store them with ids like "_design/name", while changing the resource root so that the above set of URLs could be something like (modulo an attachments handler, "_files" here, for clarity):
> /db/_baz/foo/_view/bar?limit=10
> /db/_baz/foo/_show/docid
> /db/_baz/foo/_files/index.html
> Before we commit / before 0.9.0:
> This patch is a big enough change that I think we should vote on it before I commit it. However, I'd like to get it in before 0.9.0 to avoid future confusion where trunk is incompatible with API clients and applications designed to run on our latest release.
> Sincerely,
> Chris
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.