1.5.7. /db/_design/design-doc/_show/show-name

POST /{db}/_design/{ddoc}/_show/{func}

Applies for null document.

The request and response parameters are depended upon function implementation.

Function:

Request:

  1. GET /recipes/_design/recipe/_show/description HTTP/1.1
  2. Accept: application/json
  3. Host: localhost:5984

Response:

  1. HTTP/1.1 200 OK
  2. Content-Length: 6
  3. Content-Type: text/html; charset=utf-8
  4. Date: Wed, 21 Aug 2013 12:34:07 GMT
  5. Etag: "7Z2TO7FPEMZ0F4GH0RJCRIOAU"
  6. Server: CouchDB (Erlang/OTP)
  7. Vary: Accept
  8. no doc

1.5.8. /db/_design/design-doc/_show/show-name/doc-id

GET /{db}/_design/{ddoc}/_show/{func}/{docid}

POST /{db}/_design/{ddoc}/_show/{func}/{docid}

Applies for the specified document.

The request and response parameters are depended upon function implementation.

Parameters:
  • db – Database name
  • ddoc – Design document name
  • func – Show function name
  • docid – Document ID
Response Headers:
 
  • ETag – Response signature
Query Parameters:
 
  • format (string) – Format of the returned response. Used by function
Status Codes:
  • 200 OK – Request completed successfully
  • – Query server error

Function:

  1. function(doc, req) {
  2. if (!doc) {
  3. return {body: "no doc"}
  4. } else {
  5. return {body: doc.description}
  6. }
  7. }
  1. GET /recipes/_design/recipe/_show/description/SpaghettiWithMeatballs HTTP/1.1
  2. Accept: application/json
  3. Host: localhost:5984

Response:

  1. HTTP/1.1 200 OK
  2. Content-Length: 88
  3. Content-Type: text/html; charset=utf-8
  4. Date: Wed, 21 Aug 2013 12:38:08 GMT
  5. Etag: "8IEBO8103EI98HDZL5Z4I1T0C"
  6. Server: CouchDB (Erlang/OTP)
  7. Vary: Accept
  8. An Italian-American dish that usually consists of spaghetti, tomato sauce and meatballs.

1.5.9. /db/_design/design-doc/_list/list-name/view-name

/{db}/_design/{ddoc}/_list/{func}/{view}

POST /{db}/_design/{ddoc}/_list/{func}/{view}

Applies for the view function from the same design document.

The request and response parameters are depended upon function implementation.

Function:

Request:

  1. GET /recipes/_design/recipe/_list/ingredients/by_name HTTP/1.1
  2. Accept: text/plain
  3. Host: localhost:5984

Response:

  1. HTTP/1.1 200 OK
  2. Content-Type: text/plain; charset=utf-8
  3. Date: Wed, 21 Aug 2013 12:49:15 GMT
  4. Etag: "D52L2M1TKQYDD1Y8MEYJR8C84"
  5. Server: CouchDB (Erlang/OTP)
  6. Transfer-Encoding: chunked
  7. Vary: Accept
  8. meatballs, spaghetti, tomato sauce

1.5.10. /db/_design/design-doc/_list/list-name/other-ddoc/view-name

GET /{db}/_design/{ddoc}/_list/{func}/{other-ddoc}/{view}

POST /{db}/_design/{ddoc}/_list/{func}/{other-ddoc}/{view}

Applies list function for the from the other design document.

Parameters:
  • db – Database name
  • ddoc – Design document name
  • func – List function name
  • other-ddoc – Other design document name that holds view function
  • view – View function name
Response Headers:
 
  • ETag – Response signature
  • chunked
Query Parameters:
 
  • format (string) – Format of the returned response. Used by provides() function
Status Codes:

Function:

  1. function(head, req) {
  2. var row = getRow();
  3. if (!row){
  4. return 'no ingredients'
  5. }
  6. send(row.key);
  7. while(row=getRow()){
  8. send(', ' + row.key);
  9. }
  10. }

Request:

  1. GET /recipes/_design/ingredient/_list/ingredients/recipe/by_ingredient?key="spaghetti" HTTP/1.1
  2. Accept: text/plain
  3. Host: localhost:5984

Response:

  1. HTTP/1.1 200 OK
  2. Content-Type: text/plain; charset=utf-8
  3. Date: Wed, 21 Aug 2013 12:49:15 GMT
  4. Etag: "5L0975X493R0FB5Z3043POZHD"
  5. Server: CouchDB (Erlang/OTP)
  6. Transfer-Encoding: chunked
  7. Vary: Accept
  8. spaghetti

1.5.11. /db/_design/design-doc/_update/update-name

POST /{db}/_design/{ddoc}/_update/{func}

Executes update function on server side for null document.

Function:

Request:

  1. Accept: application/json
  2. Content-Length: 10
  3. Content-Type: application/json
  4. Host: localhost:5984
  5. "something"

Response:

  1. HTTP/1.1 404 Object Not Found
  2. Cache-Control: must-revalidate
  3. Content-Length: 52
  4. Content-Type: application/json
  5. Date: Wed, 21 Aug 2013 14:00:58 GMT
  6. Server: CouchDB (Erlang/OTP)
  7. {
  8. "error": "missed",
  9. "reason": "no document to update"
  10. }

1.5.12. /db/_design/design-doc/_update/update-name/doc-id

PUT /{db}/_design/{ddoc}/_update/{func}/{docid}

Executes update function on server side for the specified document.

Parameters:
  • db – Database name
  • ddoc – Design document name
  • func – Update function name
  • docid – Document ID
Response Headers:
 
  • X-Couch-Id – Created/updated document’s ID
  • X-Couch-Update-Newrev – Created/updated document’s revision
Status Codes:
  • – No document was created or updated
  • 201 Created – Document was created or updated
  • – Query server error

Function:

  1. function(doc, req) {
  2. if (!doc){
  3. return [null, {'code': 400,
  4. 'json': {'error': 'missed',
  5. 'reason': 'no document to update'}}]
  6. } else {
  7. doc.ingredients.push(req.body);
  8. return [doc, {'json': {'status': 'ok'}}];
  9. }
  10. }
  1. POST /recipes/_design/recipe/_update/ingredients/SpaghettiWithMeatballs HTTP/1.1
  2. Accept: application/json
  3. Content-Length: 5
  4. Content-Type: application/json
  5. Host: localhost:5984
  6. "love"

Response:

  1. HTTP/1.1 201 Created
  2. Cache-Control: must-revalidate
  3. Content-Length: 16
  4. Content-Type: application/json
  5. Date: Wed, 21 Aug 2013 14:11:34 GMT
  6. Server: CouchDB (Erlang/OTP)
  7. X-Couch-Id: SpaghettiWithMeatballs
  8. X-Couch-Update-NewRev: 12-a5e099df5720988dae90c8b664496baf
  9. {
  10. "status": "ok"