Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 92831 invoked from network); 4 Mar 2009 10:45:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Mar 2009 10:45:53 -0000 Received: (qmail 55345 invoked by uid 500); 4 Mar 2009 10:45:53 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 55256 invoked by uid 500); 4 Mar 2009 10:45:52 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 55247 invoked by uid 500); 4 Mar 2009 10:45:52 -0000 Delivered-To: apmail-incubator-couchdb-commits@incubator.apache.org Received: (qmail 55244 invoked by uid 99); 4 Mar 2009 10:45:52 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Mar 2009 02:45:52 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO aurora.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Mar 2009 10:45:50 +0000 Received: from aurora.apache.org (localhost [127.0.0.1]) by aurora.apache.org (8.13.8+Sun/8.13.8) with ESMTP id n24AiIJv022485 for ; Wed, 4 Mar 2009 10:44:18 GMT Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Apache Wiki To: couchdb-commits@incubator.apache.org Date: Wed, 04 Mar 2009 10:44:18 -0000 Message-ID: <20090304104418.22364.20697@aurora.apache.org> Subject: [Couchdb Wiki] Update of "Formatting with Show and List" by JanLehnardt X-Virus-Checked: Checked by ClamAV on apache.org 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 JanLehnardt: http://wiki.apache.org/couchdb/Formatting_with_Show_and_List The comment on the change is: document show 404 handling ------------------------------------------------------------------------------ The `show` function is run with two arguments. The first is the document corresponding to the requested `docid`, and the second describes the HTTP request's query string, Accept headers, and other per-request information. The function returns an object describing its HTTP response. + + Example `show` function + + {{{ + function(doc, req) { + return { + body: "Hello World" + } + } + }}} + + If the show function is queried with document id that has no corresponding document in the database, `doc` is `null` and the submitted document shows up in `req.docId`. This is useful for creating new documents with a name, like in a wiki. + + If the show function is queried without a document id at all, doc is `null` and `req.docId` is `null`. This is useful for creating new documents where the user specifies the new document id in a user interface, like in a CMS. + + + {{{ + function(doc, req) { + if(doc) { + // regular doc display logic + } else { // document not found + if(req.docId) { + // handle unused doc id + } else { + // handle unspecified doc id + } + } + } + }}} + The request and response objects are of the same format used by `_external` functions, as documented in ExternalProcesses.