PUT /{db}/{local-doc-id}
This request creates or updates a local document.
Request
Request headers
-
Accept—optional—Valid values are:- application/json
- text/plain
-
Content-Type—Required—Must beapplication/json. -
If-Match– Required for document updates if therevquery parameter is not supplied —Revision identifier of the requested document.
Query parameters
| Name | Type | Description | Default |
|---|---|---|---|
batch
| string | Stores the document in batch mode. To use, set the value to ok. | none |
rev
| string | Revision identifier | none |
Response
Status codes
- 201 Created – Document created and stored on disk
- 202 Accepted – Document data accepted, but not yet stored on disk
- 400 Bad Request – Invalid request body or parameters
- 401 Unauthorized – Write privileges required
- 404 Not Found – Specified database or document ID doesn’t exist
- 409 Conflict – Document with the specified ID already exists or specified revision is not latest for target document
Response headers
-
Content-Type—The value can be:- application/json
- text/plain; charset=utf-8
-
ETag—Revision identifier enclosed in double quotes
Message body
The response is a JSON document that contains the following objects:
| Name | Type | Description |
|---|---|---|
id
| String | Document identifier |
ok
| Boolean | Indicates whether the operation was successful |
rev
| String | revision identifier |
Example
The following example creates a new local document with the identifier _local/RecipeLists in a database named cookbook.
Request
PUT /cookbook/_local/RecipeLists HTTP/1.1
Host: localhost:59840
Content-Type: application/json
{
"favorite-recipes": [
"LemonChicken",
"ChickenParm",
"ChickenSoup"
],
"recipes-to-try": [
"BLTSalad",
"PastaPrimavera",
"ChocolateBundtCake"
]
}
Response
HTTP/1.1 201 Created
Accept-Ranges: bytes
Content-Type: application/json
Date: Mon, 21 Apr 2014 16:45:38 GMT
Etag: "1-local"
Location: http://10.17.32.126:59840/cookbook/_local/RecipeLists
Server: CouchbaseLite 1.495
Transfer-Encoding: chunked
{
"id" : "_local/RecipeLists",
"rev" : "1-local",
"ok" : true
}