Configure Your App Services Trial (Mobile sync)

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

    Capella App Services

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

    With Capella App Services, you can:

    • Sync data between your buckets in Capella and any mobile or edge device.

    • Sync data directly between devices without a network connection to Capella App Services with Peer-to-Peer.

    • 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. Go to App Services and select the App Service you want to create an endpoint for.

    2. Go to App Endpoints and 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. (Optional) Select Enable Delta Sync to only sync parts of the document that have changed for the app users. By default, the entire document is synced.

    6. (Optional) Select Enable Import Filter to filter the server documents processed by the App Endpoint. By default, all server documents are imported.

    7. Click Create App Endpoint.

    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. Go to App Endpoints and select travel-sample-appservice.

    2. Go to Security  Access and Validation.

    3. In the text editor, replace the existing text with 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 Save.

    5. In the Changes being applied…​ dialog, click OK.

    6. Click Resume app endpoint.

    7. In the App Endpoint set to Resume dialog, click OK.

    Create an App Role for the App Endpoint

    To add an App Role for the App Endpoint:

    1. Go to Security  App Roles.

    2. Click Create App Role.

    3. In the Create App Role dialog, do the following:

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

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

      3. Click Create App Role.

    Create an App User for the App Endpoint

    To create a user for the App Endpoint:

    1. Go to Security  App Users.

    2. Click Create App User.

    3. In the Create App User page, 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.

      5. Click Create App User.

    Access the App Endpoint with the App Services REST API

    You can use a REST client to connect to the App Services Public REST API.

    To retrieve a document from the travel-sample bucket through the App Services Public REST API:

    1. Go to Connect.

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

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

    4. Paste the Public Connection URL and change 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. Select Basic Authentication.

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

    8. Send the GET request to receive the contents of the document airline_10 as the response.

    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. You can 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. Go to App Services and select an App Service.

    2. Go to App Endpoints and select travel-sample-appservice.

    3. Go to Connect.

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

    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 App Services REST API

    You can use the App Services Admin REST API to add new users and return a list of users.

    To use the App Services Admin REST API:

    Add an Allowed IP and Create an Admin Credential

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

    1. Go to App Services and select an App Service.

    2. Go to App Endpoints and click 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. In the Add Allowed IP page, you can either:

      • Click Add Current IP Address to populate the Allowed IP / CIDR Block field with your IP address.

      • Click Allow Access from Anywhere to allow any IP address to connect to your database.

      • Enter an IP address or IP address range in CIDR notation in the Allowed IP / CIDR Block field.

    7. Click Add Allowed IP.

    8. Go to App Endpoints and click travel-sample-appservice.

    9. Go to Connect.

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

    11. Click Create Admin Credential.

    12. In the Create Admin Credential page, do the following:

      1. In the Username field, enter admin.

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

      3. Click Create Admin Credential.

    Connect to the App Services Admin REST API

    You can use a REST client to connect to the App Services Admin REST API:

    1. Go to App Services and select an App Service.

    2. Go to App Endpoints and click travel-sample-appservice.

    3. Go to Connect.

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

    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 to receive the App User you created earlier.

    Add an App Services User

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

    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. Go to App Services and select an App Service.

    9. Go to App Endpoints and click travel-sample-appservice.

    10. Go to Security  App Users.

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

    12. Click travel-sample-appservice.

    13. Go to Security  App Users.

    The POST request adds the new user demo2@example.com.

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