Get Started

'Hello World' Sync

Once you've set up your environment, try on Ditto and perform your first peer-to-peer sync.

Intended to get you oriented, this article provides a streamlined process for integrating sync functionality within your app.

If you prefer building and exploring through a chat app, and so on, see Example Projects Overview.

Integrating Sync Functionality

Integrate the Ditto SDK in your codebase, set up authentication, and then start syncing offline:

1

From the top-most scope of your app's codebase, add the following to set up authentication and start syncing offline.

Swift
Kotlin
JS
Node.js
Java
C#
C++
Rust
Curl

2

Replace YOUR_APP_ID and YOUR_PLAYGROUND_TOKEN with your access credentials available from the portal.



Creating Subscriptions

To register a new sync subscription in your app. For example, the following snippet demonstrates how to establish a subscription to sync updates to documents in the cars collection with a field of color set to the value blue:

Swift
Kotlin
JS
Java
C#
C++
Rust


Sync subscriptions also support argument injection using the :argument syntax in DQL:

Swift
Kotlin
JS
Java
C#
C++
Rust



Retrieving Subscriptions

Retrieve active sync subscriptions by calling the subscriptions method on the ditto.sync namespace:

Swift
Kotlin
JS
Java
C#
C++
Rust



Canceling Subscriptions


Swift
Kotlin
JS
Java
C#
C++
Rust


You can check if a sync subscription is canceled by using the isCancelled field on the subscription object:

Swift
Kotlin
JS
Java
C#
C++
Rust




Updated 11 Jun 2024
Did this page help you?