Querying Couchbase Sync Gateway Using Postman
Learn how to install Couchbase Sync Gateway and Postman, and the couple of steps that are required to use Postman to query the Couchbase Sync Gateway.
this post discusses a convenient way to query, explore, and test the rest api exposed by the couchbase mobile sync gateway using the postman chrome developer tool. sync gateway exposes a rest, batch and stream interface that allows clients interact with it over the internet.
note: we will be discussing couchbase mobile v1.4 which is the current production release. there is a newer developer preview version 2.0 of couchbase mobile.
background
couchbase sync gateway is part of the couchbase mobile stack and is an internet-facing synchronization mechanism that securely syncs data across devices as well as between devices and the cloud. there are two ports over which the sync gateway listens to requests: the admin port (defaults to 4985 ) and the public port (defaults to 4984 ). in production deployments, the admin port is typically blocked from access over the internet.
installation of couchbase sync gateway
please follow instructions in the blog post to install the sync gateway in your mac os development environment. see the downloads site for all the available packages and see the full installation guide for complete details. to install on linux distributions other than the supported ones, see this post .
installation of postman
postman is a chrome developer tool that can be downloaded for free from the chrome browser web store .
using postman to query the couchbase sync gateway
here's how to use postman to query the couchbase sync gateway.
get the postman collections
the postman collection files and environment definition for the admin and public interface of the sync gateway are available for download from this github repo .
git clone git@github.com:couchbaselabs/syncgateway-postman-collection.git
there should be three files:
-
sync-gateway-admin.postman_collection
: this is the portman collection corresponding to the admin interface of the sync gateway. -
sync-gateway-public.postman_collection
: this is the portman collection corresponding to the public interface of the sync gateway. -
sync-gateway-environment.postman_environment
: this is the environment definitions file that defines the variables used by the admin and public collections.
launch the postman app
launching the postman app requires a couple of steps.
import the collections
follow the steps in the video below to import the collections that were downloaded in the previous step.
importing sync gateway postman collections.
import the environment file
follow the steps in below to import the environment definition corresponding to the postman collections:
importing the environment definition for admin and public interfaces.
set the appropriate environment
follow the steps in the video below to set the environment to the one that you just imported. update the values of the variables to suit your environment. make sure that the adminurl points to the sync gateway at admin port and the publicurl variable points to the sync gateway at the public port. it defaults to http://localhost:4985 and http://localhost:4984 respectively.
setting the postman environment.
that’s it! run your queries
the following is a demonstration of running a request on the admin interface:
querying the admin interface of sync gateway.
the following is a demonstration of running a request on the public interface. make sure you set the authorization header is set appropriately to use the appropriate authentication mechanism.
querying the public interface of sync gateway.
cli option
if you are interested in executing the postman collection from the command line interface, which may be the case for instance, if you want to integrate this as part of your continuous integration process, then you should check out newman , which is cli runner for postman.
for example, the command below will run the sync-gateway-admin.postman_collection with the sync-gateway-environment file.
if your sync gateway is running with ssl enabled and is using a self-signed certificate, the “-k” option will suppress validation of the cert (“insecure” ssl connection). this is not recommended in production environments.
newman run -k sync-gateway-admin.postman_collection --environment sync-gateway-environment.postman_environment --bail --delay-request 300;
next steps
the postman collections provide an easy way to query, explore and test the rest interface exposed by the sync gateway. if you see an issue in the collections definitions or if you would like to enhance it, please submit a pull request to the github repo .
Comments