This document describes the REST API exposed to access Couchbase
What it doesn't describe:
- auth scheme, on this step you might only protect your API endpoint using nginx built-in means
- expiration handling. in Couchbase database it is possible to associate with the key expiration time. This feature will be exposed later
There are several terms we are using while describing this API.
|document||Arbitrary JSON or BLOB value. It could be referenced by its ID|
|bucket||The logical storage, which contains the documents. Like database in SQL world, or collection in mongodb|
Lets assume we have a bucket named wonderland.
This section shows how to perform simple Create, Retrieve, Update and Delete operations
Create document in the bucket
You can also specify ID with POST request if you need to create the document with given ID.
Note that when you are using POST request, the server is always supposed to create the new document. This means that you will get an error if the document already exists.
Update the document
You can also specify If-Match header and the server will perform optimistic lock before updating. This operation might fail 412 Precondition Failed
If the document being updated doesn't exist, you will get 404 Not Found error
Removing document from the bucket
You can also specify If-Match header if you need to ensure you are removing know version of the document.
If the document being removed doesn't exist, you will get 404 Not Found error
Getting the document by ID.
In case when the given document ID isn't exist in the bucket you will get 404 Not Found
Use HEAD request to skip the document body
Each operation is carry ETag, which internally is CAS value. The ETag value can be used in the conditional requests with If-Match, If-None-Match. See examples of If-Match above.
Check if the key has been modified (in this case the server responds that it wasn't modified):
This section shows more advanced server feature: View indexes
One of the features of the Couchbase is ability to build efficient indexes leveraging Map/Reduce. They are called Views and you can define them on Admin Console UI.
This module allows you to query your views proxying them to Couchbase. All arguments will be transparently passed to Couchbase and the result will be streamed back.
For example we have a view all defined in the design document characters. It is simple map which will just emit all known characters (without any reduce function):
The result will look like (note: when id isn't accessible like for reduced views, the meta will be missing too)
You can pass the any of supported query parameters, like include_docs=true for example:
You can find executable spec here: http://docs.ngxcbm.apiary.io/