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:
GET /recipes/_design/recipe/_show/description HTTP/1.1
Accept: application/json
Host: localhost:5984
Response:
HTTP/1.1 200 OK
Content-Length: 6
Content-Type: text/html; charset=utf-8
Date: Wed, 21 Aug 2013 12:34:07 GMT
Etag: "7Z2TO7FPEMZ0F4GH0RJCRIOAU"
Server: CouchDB (Erlang/OTP)
Vary: Accept
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: |
|
---|---|
Response Headers: | |
| |
Query Parameters: | |
| |
Status Codes: |
|
Function:
function(doc, req) {
if (!doc) {
return {body: "no doc"}
} else {
return {body: doc.description}
}
}
GET /recipes/_design/recipe/_show/description/SpaghettiWithMeatballs HTTP/1.1
Accept: application/json
Host: localhost:5984
Response:
HTTP/1.1 200 OK
Content-Length: 88
Content-Type: text/html; charset=utf-8
Date: Wed, 21 Aug 2013 12:38:08 GMT
Etag: "8IEBO8103EI98HDZL5Z4I1T0C"
Server: CouchDB (Erlang/OTP)
Vary: Accept
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:
GET /recipes/_design/recipe/_list/ingredients/by_name HTTP/1.1
Accept: text/plain
Host: localhost:5984
Response:
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Wed, 21 Aug 2013 12:49:15 GMT
Etag: "D52L2M1TKQYDD1Y8MEYJR8C84"
Server: CouchDB (Erlang/OTP)
Transfer-Encoding: chunked
Vary: Accept
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: |
|
---|---|
Response Headers: | |
| |
Query Parameters: | |
| |
Status Codes: |
|
Function:
function(head, req) {
var row = getRow();
if (!row){
return 'no ingredients'
}
send(row.key);
while(row=getRow()){
send(', ' + row.key);
}
}
Request:
GET /recipes/_design/ingredient/_list/ingredients/recipe/by_ingredient?key="spaghetti" HTTP/1.1
Accept: text/plain
Host: localhost:5984
Response:
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Date: Wed, 21 Aug 2013 12:49:15 GMT
Etag: "5L0975X493R0FB5Z3043POZHD"
Server: CouchDB (Erlang/OTP)
Transfer-Encoding: chunked
Vary: Accept
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:
Accept: application/json
Content-Length: 10
Content-Type: application/json
Host: localhost:5984
"something"
Response:
HTTP/1.1 404 Object Not Found
Cache-Control: must-revalidate
Content-Length: 52
Content-Type: application/json
Date: Wed, 21 Aug 2013 14:00:58 GMT
Server: CouchDB (Erlang/OTP)
{
"error": "missed",
"reason": "no document to update"
}
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: |
|
---|---|
Response Headers: | |
| |
Status Codes: |
|
Function:
function(doc, req) {
if (!doc){
return [null, {'code': 400,
'json': {'error': 'missed',
'reason': 'no document to update'}}]
} else {
doc.ingredients.push(req.body);
return [doc, {'json': {'status': 'ok'}}];
}
}
POST /recipes/_design/recipe/_update/ingredients/SpaghettiWithMeatballs HTTP/1.1
Accept: application/json
Content-Length: 5
Content-Type: application/json
Host: localhost:5984
"love"
Response:
HTTP/1.1 201 Created
Cache-Control: must-revalidate
Content-Length: 16
Content-Type: application/json
Date: Wed, 21 Aug 2013 14:11:34 GMT
Server: CouchDB (Erlang/OTP)
X-Couch-Id: SpaghettiWithMeatballs
X-Couch-Update-NewRev: 12-a5e099df5720988dae90c8b664496baf
{
"status": "ok"