9

I was looking for the couchbase REST API's for insert/update a document in given bucket, but I couldn't find any. Does anybody knows if such API exist?

Only API i could find is for updating design document:

http://docs.couchbase.com/couchbase-manual-2.5/cb-rest-api/#design-documents-rest-api

zer0Id0l
  • 1,374
  • 4
  • 22
  • 36
  • So you cannot use the SDKs? They are going to be far and away better to do any kind of operations. – NoSQLKnowHow Jan 24 '15 at 22:15
  • [here's](https://github.com/npocmaka/CouchbaseDocumentUtils) a pretty simple (with sketchy examples) class that can update/delete/get/create documents with the admin user – npocmaka Aug 25 '16 at 14:25

5 Answers5

10

It is not documented (thus, probably not supported), but you can do this using the same base URL as the couchbase bucket API (see table 4). The complete path is:

...hostname:8091/pools/default/buckets/{bucketname}/docs/{docid}

To confirm this, just go to your couchbase web console, and use your builtin browser developer tools to check all network queries, and hit save button. You can verify this is the actual REST endpoint that the couchbase web console hits when you open or save a document.

It uses basic HTTP auth. But, instead of bucket password it needs Admin credentials.

Important: You should not rely on this for high performance operations. Performance on number of gets and sets operations using this undocumented REST endpoint is way too slow compared to couchbase official SDK which is optimized protocol that does not carry the HTTP overhead.

L. Holanda
  • 4,432
  • 1
  • 36
  • 44
2

There is no REST API for CRUD operations in Couchbase. If you must use REST, you'll pretty much have to use an external service as a proxy. You can probably use the Couchbase mobile sync gateway as a sort of CRUD service, or roll your own. You can find an example here: https://github.com/couchbaselabs/couchbase-rest-api-rails

David Ostrovsky
  • 2,461
  • 12
  • 13
  • This might be late entry but if anyone want to do the same then this is what i tried and is woring with couchbase 7 beta: curl --location --request POST 'http://localhost:8091/_p/query/query/service' \ --header 'Authorization: Basic YWRtaW46YWRtaW4x' \ --header 'Content-Type: application/json' \ --data-raw '{ "statement": "INSERT INTO `bucket1` (KEY, VALUE)\r\nVALUES (\"key7\", { \"type\" : \"hotel\", \"name\" : \"new hotel3\" })" }' – focode Mar 09 '21 at 09:41
2

Created a simple sample that shows CRUD on an existing bucket in Couchbase at:

http://blog.arungupta.me/crud-java-application-with-couchbase-java-ee-and-wildfly/

This is then exposed as a REST API.

Arun Gupta
  • 3,965
  • 5
  • 31
  • 39
1

REST API's for insert/update a document in given bucket

http://localhost:8092/bucket name/doucmnetId

application/json

{ insert your json data }

create a POST request to your couchbase you can create the document.

create a PUT request you can update your document in couchbase.

Prabitha
  • 113
  • 10
-3

There is the Couchbase Buckets REST API documentations that allows for fine grain control about buckets and bucket operations in the cluster.

But if you can, using the SDKs would be advised and better overall for any kind of operations.

sweetiewill
  • 570
  • 2
  • 10