Connect your Apps to an App Endpoint

      +

      Couchbase provides Couchbase Lite: an embedded, NoSQL JSON-document Style database for your mobile apps.

      You can use Couchbase Lite as a standalone embedded database within your mobile apps, or with Couchbase Capella’s App Endpoints to provide a complete cloud to edge synchronized solution. Couchbase Lite runs on the following platforms:

      Setting up the Connection

      You must to set up the permitted addresses on your App Endpoint configuration before your mobile application can connect to it.

      1. From the project page, select the App Services tab.

      2. From the App Services screen, you can select the App Endpoints tab.

        Select app endpoint
        Figure 1. Select App Endpoint

        The next screen will allow you to configure the endpoint.

        The connection configuration screen can be found under connect of your App Endpoint.

        locate connect tab
        Figure 2. Locate App Endpoint connect tab

      From here, you can configure the App Endpoint connection settings:

      Public Connection

      This setting is created when the App Endpoint is created. This is the address which your mobile application uses to connect to the endpoint.

      Public Certificate

      The public certificate is a trusted CA signed certificate. You can copy or download the endpoint’s SSL public certificate to bundle into your mobile application.

      Since this is a trusted certificate, certificate pinning is optional, please consult your own security policies.

      Capella rotates the certificate yearly.

      If you have pinned the certificate, you will have to update your app to use the new certificate when the old one expires.

      Capella will notify you via email starting 3 months before the certificate is scheduled to expire (if you have enabled email notifications on your account.)

      To update your app with the new certificate ahead of the scheduled expiration, please contact Support.

      If, however, you do not pin the certificate, your app will continue to operate after certificate rotation with no downtime and no action required.

      Endpoint for Admin Access to the database

      To ensure your service is as secure as possible, the App Endpoint uses a separate URL for executing REST API administration functions.

      Manage Credentials for user administration and metrics access

      You will need to set up credentials for accessing the endpoint’s administration and metrics functions. Click the Manage Credentials → link to access the Manage Credentials screen, then click on + Create Admin Credential:

      create admin credential
      Figure 3. Creating Admin Credentials for an App Endpoint
      Allowed IPs

      Any IP that requires a connection to the endpoint must be registered here. Click on Go to Allowed IPs > to access the screen, then click the + Add Allowed IP link.

      add allowed ip

      You can fill in the allowed IP address, or click Add Current IP Address to fill in the IP address of the machine you’re using.

      You can also press Allow Access from Anywhere to allow access to your endpoint from any location.

      You can add an expiry date to the entry, which may be used, for example, to allow temporary access to the endpoint for testing.

      Syncing Data to a Client Application

      Once the App Service has been configured, data synchronisation can be initiated from client application using calls to the Couchbase API.

      In this example, first open the local database for syncing from the Capella App Service.

      The client application uses the address of the endpoint to sync its local databases. The App Endpoint address can be found under the Connect tab of App Endpoint configuration (See Figure 2).

      let db = try! Database(name: "travel-sample")
      
      guard let targetURL = URL(string: "wss://gaoca1lnIxwdumid.apps.endpoint.com:4984/test-endpoint")
      else {
          fatalError("Invalid URL")
      }

      Now create a configuration linking the local database to the App Endpoint. Set the sync to run bidirectionally.

      The authenticator takes the username and password set up when the App Endpoint’s user was created (See Create App Users).

      let targetEndpoint = URLEndpoint(url: targetURL)
      
      var config = ReplicatorConfiguration(database: db, target: targetEndpoint)
      config.replicatorType = .pushAndPull
      config.continuous = false
      
      config.authenticator = BasicAuthenticator(
          username: "test-user",
          password: "password")

      Finally, start syncing.

      let replicator = Replicator.init(config: config)
      replicator.start()