PUT /{db}

In this document

This request creates a new database.

The database name must begin with a lowercase letter. The legal characters for the database name are: lowercase letters [a-z], digits [0-9], and special characters [$_()+-/].

Request


Request headers

This request does not have any required headers.

Query parameters

This request does not use query parameters.

Message body

This request does not use a message body.

Response


Status codes

Response headers

Message body

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

NameTypeDescription
error StringError message
ok BooleanIndicates whether the operation was successful
status IntegerHTTP error code

Example


The following example creates a new database named cookbook.

Request

PUT /cookbook HTTP/1.1
Host: localhost:59840

Response

HTTP/1.1 201 Created
Server: CouchbaseLite 1.485
Location: http://localhost:59840/cookbook
Accept-Ranges: bytes
Content-Length: 18
Content-Type: application/json
Date: Sun, 08 Dec 2013 20:17:16 GMT
{
  "ok" : true
}

The following example shows the error you receive when trying to create a database that already exists:

Request

PUT /cookbook HTTP/1.1
Host: localhost:59840

Response

HTTP/1.1 412 Precondition Failed
Transfer-Encoding: chunked
Accept-Ranges: bytes
Content-Type: application/json
Server: CouchbaseLite 1.485
Date: Mon, 09 Dec 2013 19:26:09 GMT
{
  "status" : 412,
  "error" : "file_exists"
}

The following example shows the error you receive when you specify an invalid database name. The name for the database, ACookbook, is invalid because it begins with an uppercase letter.

Request

PUT /ACookbook HTTP/1.1
Host: localhost:59840

Response

HTTP/1.1 400 Bad Request
Transfer-Encoding: chunked
Accept-Ranges: bytes
Content-Type: application/json
Server: CouchbaseLite 1.486
Date: Thu, 12 Dec 2013 19:42:12 GMT
{
  "status" : 400,
  "error" : "Invalid database\/document\/revision ID"
}