You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by Apache Wiki <wi...@apache.org> on 2009/02/24 00:47:54 UTC
[Couchdb Wiki] Update of "Formatting with Show and List" by PaulDavis
Dear Wiki user,
You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.
The following page has been changed by PaulDavis:
http://wiki.apache.org/couchdb/Formatting_with_Show_and_List
The comment on the change is:
Redirect example
------------------------------------------------------------------------------
}
}}}
+
+ == Other Fun Things ==
+
+ === Stopping iteration in a `_list` ===
+
+ If you want to terminate iteration of a `_list` early you can return a `{stop: true}` JSON object from any of the calls to the function that include a row object.
+
+ === Sending a Redirect ===
+
+ In the call to `_show` or when `_list` is called with a head object you can control the headers and status code sent to the client. An example of this would be to send a redirect notification.
+
+ {{{
+ function(doc)
+ {
+ return {"code": 302, "body": "See other", "headers": {"Location": "/"}};
+ }
+ }}}
+
+ {{{
+ function(head, row, req, row_info) {
+ if (head) {
+ return {"code": 302, "body": "See other", "headers": {"Location": "/"}};
+ } else if (row) {
+ return {stop: true};
+ } else {
+ return "."
+ }
+ }
+ }}}
+
Hopefully this is enough to get started. For a more complete set of examples, see the CouchDB test suite, especially show_documents.js and list_views.js