To obtain an existing design document from a given bucket, you
need to access the design document from the corresponding bucket
using a GET request, as detailed in the table
below.
| Method | GET /bucket/_design/design-doc |
| Request Data | Design document definition (JSON) |
| Response Data | Success and stored design document ID |
| Authentication Required | optional |
| Return Codes | |
| 200 | Request completed successfully. |
| 401 | The item requested was not available using the supplied authorization, or authorization was not supplied. |
| 404 | The requested content could not be found. The returned content will include further information, as a JSON object, if available. |
For example, to get the existing design document from the bucket
sales for the design document
byfield:
shell> curl -X GET \ -H 'Content-Type: application/json' \ 'http://user:password@192.168.0.77:8092/sales/_design/dev_byfield
Through curl this will download the design
document to the file dev_byfield filename.
If the bucket does not have a password, you can omit the authentication information. If the view does not exist you will get an error:
{ "error":"not_found", "reason":"missing" }
The HTTP response header will include a JSON document containing
the metadata about the design document being accessed. The
information is returned within the
X-Couchbase-Meta header of the returned data.
You can obtain this information by using the -v
option to the curl.
For example:
shell> curl -v -X GET \ -H 'Content-Type: application/json' \ 'http://user:password@192.168.0.77:8092/sales/_design/ * About to connect() to 192.168.0.77 port 8092 (#0) * Trying 192.168.0.77... % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* connected * Connected to 192.168.0.77 (192.168.0.77) port 8092 (#0) * Server auth using Basic with user 'Administrator' > GET /sales/_design/something HTTP/1.1 > Authorization: Basic QWRtaW5pc3RyYXRvcjpUYW1zaW4= > User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5 > Host: 192.168.0.77:8092 > Accept: */* > Content-Type: application/json > < HTTP/1.1 200 OK < X-Couchbase-Meta: {"id":"_design/dev_sample","rev":"5-2785ea87","type":"json"} < Server: MochiWeb/1.0 (Any of you quaids got a smint?) < Date: Mon, 13 Aug 2012 10:45:46 GMT < Content-Type: application/json < Content-Length: 159 < Cache-Control: must-revalidate < { [data not shown] 100 159 100 159 0 0 41930 0 --:--:-- --:--:-- --:--:-- 53000 * Connection #0 to host 192.168.0.77 left intact * Closing connection #0
The metadata matches the corresponding metadata for a data document.