POST /{db}

In this document

This request creates a new document in the specified database. You can either specify the document ID by including the _id object in the request message body, or let the software generate an ID.

Request


Request headers

The request uses the following headers:

Query parameters

The request uses the following query parameter:

NameTypeDescriptionDefault
batch stringStores the document in batch mode. To use, set the value to ok.none

Response


The response is a JSON document that contains the following objects:

NameTypeDescription
id StringDocument identifier
ok BooleanIndicates whether the operation was successful
rev Stringrevision identifier

Example


The following request creates a new document in a database named cookbook.

Request

POST /cookbook HTTP/1.1
Host: localhost:59840
Content-Type: application/json
{
    "description": "Chicken topped with mozzarella and parmesan cheese",
    "servings": 4,
    "title": "Chicken Parmagiana"
}

Response

HTTP/1.1 201 Created
Accept-Ranges: bytes
Content-Length: 115
Content-Type: application/json
Date: Fri, 13 Dec 2013 01:57:54 GMT
Etag: "1-ed0ebedd2fab89227b352f6455a08010"
Location: http://localhost:59840/cookbook/209BB170-C1E0-473E-B3C4-A4533ACA3CDD
Server: CouchbaseLite 1.486
{
  "id" : "209BB170-C1E0-473E-B3C4-A4533ACA3CDD",
  "rev" : "1-ed0ebedd2fab89227b352f6455a08010",
  "ok" : true
}

The following example creates a new document with the identifier LemonChicken in a database named cookbook.

Request

POST /cookbook
Host: localhost:59840
Content-Type: application/json
{
    "_id": "LemonChicken",
    "description": "Chinese lemon chicken",
    "servings": 4,
    "title": "Lemon Chicken"
}

Response

HTTP/1.1 201 Created
Accept-Ranges: bytes
Content-Type: application/json
Date: Fri, 13 Dec 2013 02:31:46 GMT
Etag: "1-78abf9a6508671ba8338e4ef6daa910a"
Location: http://localhost:59840/cookbook/LemonChicken
Server: CouchbaseLite 1.486
Transfer-Encoding: chunked
{
  "id" : "LemonChicken",
  "rev" : "1-78abf9a6508671ba8338e4ef6daa910a",
  "ok" : true
}