REST API
The Couchbase Lite REST API provides HTTP access to your databases. This introduces the REST API and includes an overview of the available resources.
Notation Conventions
Within the paths of the URIs presented in these guides:
-
Path segments that start with an underscore character are static components of the URI that you use exactly as given. For example:
_replicate. -
Path segments that are not preceded by an underscore character represent variables that you replace with your own value. These variables are usually enclosed in brackets as a reminder. For example:
{db}or<db>.
For example, suppose you have a database named cookbook. In the database, the IDs for recipes start with the string "recipe" and IDs for design documents start with the string "ddoc". The following table shows examples of values you might use for the URI path in the request that you send to the database:
| Path | Sample value |
|---|---|
/<db>
|
/cookbook
|
/<db>/_changes
|
/cookbook/_changes
|
/<db>/<doc>
|
/cookbook/recipe123
|
/_replicate
|
/_replicate
|
HTTP requests and responses
The Couchbase Lite REST API uses the Hypertext Transfer Protocol (HTTP). Each API is an HTTP request. For each HTTP request that you send, you receive an HTTP response. HTTP requests consist of a request line, header lines, and a message body. HTTP responses consist of a status line, header lines, and a message body.
The examples in this document are shown in the basic HTTP format.
The message body for both the HTTP requests and HTTP responses is formatted as a JSON document. To learn more about JSON, check out JSON.org or the W3Schools JSON Tutorial.
Each HTTP response contains a status code. The following table lists some of the status codes returned by Couchbase Lite:
| HTTP Status Code | Returned String |
|---|---|
| 200 | OK |
| 201 | Created |
| 202 | Accepted |
| 400 | Bad data encoding |
| 400 | bad_request |
| 400 | Invalid attachment |
| 400 | Invalid database/document/revision ID |
| 400 | Invalid JSON |
| 400 | Invalid parameter in HTTP query or JSON body |
| 401 | unauthorized |
| 403 | forbidden |
| 404 | Attachment not found |
| 404 | deleted |
| 404 | not_found |
| 406 | not_acceptable |
| 409 | conflict |
| 412 | file_exists |
| 415 | bad content type |
| 500 | Application callback block failed |
| 500 | Attachment store error |
| 500 | Database error! |
| 500 | Database locked |
| 500 | Internal error |
| 500 | Invalid data in database |
| 502 | Invalid response from remote replication server |
Server
APIs that operate at the server level
Database
APIs that operate on databases
Document
APIs that operate on documents
Local Document
APIs that operate on local documents
Design Document
APIs that operate on design documents
Authentication
APIs that authenticate users