Basic usage of Public REST API (sync gateway)

Priya - can you tell me the curl -x POST syntax for loading the documents? I can’t find this anywhere.
Thanks!
Jackie

Assuming you are referring to the SGW REST API. There are available here ? The specific POST API that you are looking for is documented here.

Wasn’t entirely clear, but if you are specifically looking with the curl syntax, you can use the following SGW postman collection and then use POSTMAN client to generate the corresponding curl syntax for you.

(Similar to screenshot below)

yes that is what I’m looking for, how can I give a file to it, e.g., my file looks like this:[root@rayv-dbs2 ~]# cat jrb.json
{
“docs”: [
{ “forename”: “Gavin”, “surname”: “Cooper”, “type”: “person” },
{ “forename”: “Gavin”, “surname”: “Cooper”, “type”: “person” },
{ “forename”: “Gavin”, “surname”: “Cooper”, “type”: “person” },
{ “forename”: “Gavin”, “surname”: “Cooper”, “type”: “person” },
{ “forename”: “Gavin”, “surname”: “Cooper”, “type”: “person” },
{ “forename”: “Gavin”, “surname”: “Cooper”, “type”: “person” },
{ “forename”: “Gavin”, “surname”: “Cooper”, “type”: “person” },
{ “forename”: “Gavin”, “surname”: “Cooper”, “type”: “person” },
{ “forename”: “Gavin”, “surname”: “Cooper”, “type”: “person” }
],
“new_edits”: true
}

I am using couchbase 5.0.1 CE on linux (centos)

Hi team. I am new to couchbase. I asked if is it possible in a sync function to make request post to another application in order to throw it specific document in the sync gateway?
any help is welcome.

You could define a web hook handler that listens to document change requests and the posts it to specified URLs. This would be defined as part of configuration file and not sync function.

Document changes (creations, updates, and deletions) that are made through Sync Gateway’s Public REST API, including document changes that result from Couchbase Lite push replications, raise events that webhook event handlers listen for.

More details specified here - Couchbase Capella for Mobile Developers

“event_handlers”: {
“document_changed”: [
{
“handler”: “webhook”,
“url”: “http://someurl.com
}
]
}

Would the above work?

thank you for your interresting response @priya.rajagopal . i will try this .

@layoussou I think you have a couple of further options:

  1. Couchbase Enterprise has now an eventing section where you can write JS functions to react to data changes and, for example, curl an external REST service.

  2. With Couchbase Kafka connector you can have Couchbase data changes published on a Kafka topic you can listen to with an another application.

Is the git link - git clone git@github.com:couchbaselabs/SyncGateway-Postman-Collection.git still working ?

Try this instead
git clone https://github.com/couchbaselabs/Couchbase-Sync-Gateway-Postman-Collection.git

The repo was renamed. Will update the URL in the blog posts

1 Like