Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Querying Couchbase Sync Gateway Using Postman

DZone's Guide to

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.

· Database Zone
Free Resource

Traditional relational databases weren’t designed for today’s customers. Learn about the world’s first NoSQL Engagement Database purpose-built for the new era of customer experience.

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:

  1. Sync-Gateway-Admin.postman_collection: This is the Portman collection corresponding to the Admin interface of the Sync Gateway.

  2. Sync-Gateway-Public.postman_collection: This is the Portman collection corresponding to the Public interface of the Sync Gateway.

  3. 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.

Learn how the world’s first NoSQL Engagement Database delivers unparalleled performance at any scale for customer experience innovation that never ends.

Topics:
couchbase ,database ,tutorial ,sync gateway ,postman

Published at DZone with permission of Priya Rajagopal. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}