미분류

Exploring the Public and User Channels in Couchbase Sync Gateway

Sync Function is one of the fundamental components of Sync Gateway: its main responsibility is to define which user has access to which documents. In this screencast, you’ll learn how to use the public channel (also known as the ! channel) to synchronize documents to users that haven’t logged into your app yet. This feature is particularly useful when designing the on boarding journey with dynamic data that can be changed on the backend and pulled automatically when the user starts the app for the first time. We’ll consider a note taking application and explore the following:

  1. Use the public channel to insert the Getting Started note, you can think of it as the tutorial note when the user starts the app for the first time
  2. Map the note created by a registered user to a channel that is only accessible by that user
  3. Enforce write permissions with the requireUser 방법
  4. Test the Sync Function with curl commands

Find the code for this lesson

You can find the Sync Gateway config file below:

And the curl commands to test the Sync Function:

  1. Persist a Public Note via the Admin API
    curl -X POST https://localhost:4985/notes/ 
        -H "Content-Type: application/json" 
        -d '{"security": "public", "title": "Getting Started"}'
  2. User Authentication
    curl -vX POST https://localhost:4984/notes/_session 
        -H "Content-Type: application/json" 
        -d '{"name": "william", "password": "pass"}'
  3. Persist a User Note
    curl -X POST https://localhost:4984/notes/ 
        -H "Content-Type: application/json" 
        -H "Cookie: SyncGatewaySession=PASTE_COOKIE_VALUE" 
        -d '{"user_name": "william", "title": "Overview of the user journey"}'
이 기사 공유하기

작가

James Nocentini is the Technical Writer in charge of the documentation for Couchbase Mobile. Previously, he worked as a Developer Advocate and before that as a front-end developer for HouseTrip. He also enjoys writing Android tutorials for raywenderlich.com in his spare time.

댓글 남기기

카우치베이스 카펠라를 시작할 준비가 되셨나요?

개발 시작하기

NoSQL을 탐색하고, 리소스를 찾아보고, 튜토리얼을 시작하려면 개발자 포털을 확인하세요.

카펠라 프리 사용하기

단 몇 번의 클릭으로 카우치베이스(Couchbase)를 직접 체험해 보세요. Capella DBaaS는 시작하기 가장 쉽고 빠른 방법입니다.

연락해

Couchbase 제품군에 대해 더 알고 싶으신가요? 저희가 도와드리겠습니다.