Não categorizado

Exploring the Public and User Channels in Couchbase Sync Gateway

2 MIN DE LEITURA

A 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 method
  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"}'
Compartilhe este artigo

Autor

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.

Deixe um comentário

Pronto para começar com o Couchbase Capella?

Começar a construir

Confira nosso portal para desenvolvedores para explorar o NoSQL, navegar por recursos e começar com tutoriais.

Use o Capella free

Coloque a mão na massa com o Couchbase em apenas alguns cliques. O Capella DBaaS é a maneira mais fácil e rápida de começar.

Entre em contato

Quer saber mais sobre as ofertas do Couchbase? Deixe-nos ajudar.