couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "Formatting with Show and List" by JanLehnardt
Date Wed, 04 Mar 2009 10:44:18 GMT
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.
  

Mime
View raw message