Configure Your App Services Trial (Mobile sync)

  • tutorial
    +
    Configure App Services to test out a mobile application with your trial database.

    About Capella App Services

    Capella App Services is a fully-managed application backend designed for mobile and edge applications. Use Capella App Services with an embedded Couchbase Lite database in your applications.

    Capella App Services syncs data between your buckets in Capella and any mobile or edge devices. An app that uses Couchbase Lite can directly sync data between devices with Peer-to-Peer, even without a network connection to Capella App Services.

    You can also authenticate and manage mobile and edge users through App Services Endpoints.

    Prerequisites

    Create An App Endpoint For Your Trial App Service

    To create an App Endpoint:

    1. From the Start page, click Linked App Service.

    2. On the App Endpoints page, click Create App Endpoint.

    3. In the App Endpoint Name field, enter travel-sample-appservice.

    4. In the Linked Bucket list, select travel-sample.

    5. Click Create App Endpoint.

    The App Endpoint takes a few minutes to deploy. Until it deploys, the App Endpoint’s status shows as Offline.

    Configure The App Endpoint With An Access Control Policy

    To configure access control for your new App Endpoint:

    1. From the App Endpoints page, click your travel-sample-appservice.

    2. Go to Security  Access and Validation.

    3. In the text editor, paste the following JavaScript code:

      function (doc, oldDoc, meta) {
        if (doc.channels) {
            // If channels list is specified in document, assign doc to the channels
           channel(doc.channels);
        }
        else {
          // assign to public channel (which is accessible to all users)
          channel ("!")
        }
      }
    4. Click Apply.

    5. Click Resume app endpoint.

    Create An App Role For The App Endpoint

    To add an App Role for the App Endpoint:

    1. From the Security tab, go to App Roles.

    2. Click Create App Role.

    3. Do the following:

      1. In the App Role Name field, enter admin.

      2. In the Admin Channels field, enter an asterix (*) and press Enter.

    4. Click Create App Role.

    Create An App User For The App Endpoint

    To create a user for the App Endpoint:

    1. From the Security tab, go to App Users.

    2. Click Create App User.

    3. Do the following:

      1. In the App Username field, enter a username for the new app user.

      2. In the Password field, enter a password for the new app user.

      3. In the Admin Channels field, enter an asterix (*) and press Enter.

      4. In the Admin App Roles field, enter admin and press Enter.

    4. Click Create App User.

    Access The App Endpoint With The Public REST API

    You can use a REST client to connect to the Public REST endpoint.

    To retrieve a document from the travel-sample bucket via the Public REST endpoint:

    1. Go to Connect.

    2. Next to the Public Connection field, click Copy to Clipboard.

    3. In your REST Client, create a GET request.

    4. Paste the Public Connection URL and change the wss to https.

    5. Add /airline_10 to the end of the URL.

      Your URL should look similar to https://123456789.apps.capella.com:4984/travel-sample-appservice/airline_10

    6. Choose Basic Authentication.

    7. Enter the username and password for the App User you created.

    8. Send the GET request.

      You should see the contents of the document airline_10.

    For more information about the Public REST API, see Public REST API.

    Connect a Couchbase Lite App to the Capella App Service Endpoint

    Couchbase Lite is an embedded database. Use it to embed data processing and storage in applications that run on mobile and IoT devices, allowing apps to locally store and access data without an Internet connection.

    Couchbase Lite embedded apps can connect to App Endpoints and sync data with each other and the Couchbase Capella backend over a websockets-based data sync protocol.

    To connect Couchbase Lite to your App Endpoint:

    1. From the Start page, click Linked App Service.

    2. On the App Endpoints page, click your travel-sample-appservice.

    3. Go to Connect.

    4. Next to the Public Connection field, click Copy to Clipboard.

    5. Use a Couchbase Lite sample application to connect to your App Service:

      • Swift (iOS, macOS): Replace the URLEndpoint in the sample code with your App Endpoint Public Connection URL.

      • Kotlin (Android): Replace the URLEndpoint in the sample code with your App Endpoint Public Connection URL.

      • Java (Android): Replace the URLEndpoint in the sample code with your App Endpoint Public Connection URL.

      • .Net (Desktop, Xamarin): Replace the URLEndpoint in the sample code with your App Endpoint Public Connection URL.

      • Java (Desktop): Replace the URLEndpoint in the sample code with your App Endpoint Public Connection URL.

      • C (Desktop, Mobile, Embedded): Replace the CBLEndpoint_CreateWithURL in the sample code with your App Endpoint Public Connection URL.

    (Optional) Administer App Users With The Admin REST API

    You can administer users with the Admin REST endpoint. You can use the REST API to return a list of users and add a new user.

    To use the Admin REST API, you need to Add An Allowed IP and Create An Admin Credential.

    Add An Allowed IP and Create An Admin Credential

    To add an allowed IP address and create an admin credential:

    1. From the Start page, click Linked App Service.

    2. On the App Endpoints page, click your travel-sample-appservice.

    3. Go to Connect.

    4. Under Allowed IP Addresses, click Go to Allowed IP Addresses.

    5. Click Add Allowed IP Address.

    6. Do one of the following:

      1. Click Add Current IP Address.

      2. In the IP Address/CIDR Block field, enter an IP address or IP address range in CIDR notation.

    7. Click Add IP.

    8. Go to App Endpoints.

    9. On the App Endpoints page, click your travel-sample-appservice.

    10. Go to Connect.

    11. Under Admin and Metrics Credentials, click Manage Credentials.

    12. Click Create Admin Credential.

    13. Do the following:

      1. In the Username field, enter admin.

      2. In the Password field, enter a password for the admin credential.

    14. Click Create Admin Credential.

    Connect to The Admin REST Endpoint

    You can use a REST client to connect to the Admin REST endpoint:

    1. From the Start page, click Linked App Service.

    2. On the App Endpoints page, click your travel-sample-appservice.

    3. Go to Connect.

    4. Next to the Admin Connection field, click Copy to Clipboard.

    5. In your REST client, create a GET request.

    6. Paste the Admin Connection URL.

    7. Add /_user to the end of the URL.

      Your URL should look similar to https://123456789.apps.capella.com:4985/travel-sample-appservice/_user/

    8. Select Basic Authentication.

    9. Enter the Admin Credential you created.

    10. Send the GET request.

      The request returns the App User you created.

    Add An App Services User

    To add a new App Services User with the Admin REST endpoint:

    1. In your REST client, create a POST request.

    2. Paste the Admin Connection URL.

    3. Add /_user to the end of the URL.

      Your URL should look similar to https://123456789.apps.capella.com:4985/travel-sample-appservice/_user/

    4. Select Basic Authentication.

    5. Enter the Admin Credential you created.

    6. In the request body, add the following JSON code:

      {
        "name": "demo2@example.com",
        "password": "password",
        "admin_channels": [
          "string"
        ],
        "disabled": false
      }
    7. Send the POST request.

    8. In the Capella UI, return to the App Endpoints page.

    9. Click your travel-sample-appservice.

    10. Go to Security  App Users.

      The POST request adds a new user, demo2@example.com.

    For more information about the Admin REST API, see Admin REST API.