PUT /{db}/{design-doc-id}

In this document

This request creates or updates a design document.

Request


Request headers

This request does not have any required headers.

Query parameters

This request does not use query parameters.

Message body

The message body is a JSON document that one or more view definitions and some other fields.

Response


Status codes

Response headers

This response uses only standard HTTP headers.

Message body

The response contains a JSON document that contains some of the following objects:

NameTypeDescription
id StringDesign document identifier
ok BooleanIndicates whether the operation was successful
rev IntegerRevision identifier

Example


The following example creates a design document with the ID _design/beer4 in a database named beer-db. The design document defines two views, brewery_beers and by_location. Both views define a map function, but only the by_location view defines a reduce function.

Request

PUT /beer-db/_design/beer4 HTTP/1.1
Host: localhost:59840
{
    "language" : "javascript",
    "views" : {
        "brewery_beers" : {
            "map" : "function(doc) {if (doc.brewery_id) {emit(doc.brewery_id)}}"
        }
    }
}

Response

HTTP/1.1 201 Created
Accept-Ranges: bytes
Content-Length: 93
Content-Type: application/json
Date: Wed, 23 Apr 2014 22:55:42 GMT
Etag: "1-2ed3e22a2f64b5364028e5b5842fcf41"
Location: http://10.17.32.126:59840/beer-db/_design/beer4
Server: CouchbaseLite 1.495
{
   "id": "_design/beer4",
   "rev": "1-2ed3e22a2f64b5364028e5b5842fcf41",
   "ok": true
}