Applies show function for null 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}
}
}
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
Applies show function 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}
}
}
Request:
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.
Applies list function for the view function from the same design document.
The request and response parameters are depended upon function implementation.
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/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
Applies list function for the view function from the other design document.
The request and response parameters are depended upon function implementation.
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
Executes update function on server side for null 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'}}];
}
}
Request:
POST /recipes/_design/recipe/_update/ingredients HTTP/1.1
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"
}
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'}}];
}
}
Request:
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"
}