Configure Your Free Tier App Services (Mobile sync)
- Capella Operational
- tutorial
Configure App Services to test out a mobile application with your free tier operational cluster.
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 application data from linked collections in your App Endpoint on 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
-
You deployed a Couchbase Capella free tier operational cluster. For more information, see Deploy Your Free Tier Operational Cluster.
-
Your free tier operational cluster has the
travel-sample
bucket. For more information, see Import Data with the Capella UI. -
You deployed your free tier App Services. For more information, see Deploy Capella Free Tier App Services.
-
You have a REST Client, such as Postman or HTTPie installed and configured.
Create an App Endpoint for Your Free Tier App Service
To create an App Endpoint:
-
Go to App Services and select the App Service you want to create an endpoint for.
-
Go to App Endpoints and click Create App Endpoint.
-
In the App Endpoint Name field, enter travel-sample-appservice.
-
In the Linked Bucket list, select travel-sample.
-
In the Scope list, select inventory.
-
Go to the Linked Collections table and link the airline collection.
-
Click Create App Endpoint.
If a large number of collections are linked at one time, an initializing state will occur. During this phase, you can update general configuration, link or unlink more collections, change Auth Providers or the Access Control Function. After the linking of collections is completed, the App Endpoint’s status shows as Offline. You can resume the endpoint by selecting the desired endpoint from the App Endpoints menu and clicking the Resume App Endpoint button in App Endpoint settings.
Configure the App Endpoint with an Access Control Policy
To configure access control for your new App Endpoint:
-
Go to App Endpoints and select travel-sample-appservice.
-
Go to
. -
Click the airline collection.
-
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 ("!") } }
-
Click Save.
-
Click Resume app endpoint.
-
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:
-
Go to
. -
Click Create App Role.
-
In the App Role Name field, enter
admin
. -
In the Admin Channels field of the airline collection, enter an asterix (*) and press Enter.
-
Click Save.
Create an App User for the App Endpoint
To create a user for the App Endpoint:
-
Go to
. -
Click Create App User.
-
In the Create App User page, do the following:
-
In the App User name field, enter a username for the new app user.
-
In the Password field, enter a password for the new app user.
-
(Optional) Click the Configure Access Grants drop down.
-
(Optional) In the Assigned App Roles field, select
admin
from the dropdown menu. -
(Optional) In the Assign Channels field, enter an asterix (*) and press Enter.
-
-
Click Create App User.
-
App Users can inherit their assigned channels directly from roles or be specifically assigned channels on a per user basis. |
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:
-
Go to Connect.
-
Next to the Public Connection field, click Copy.
-
In your REST Client, create a GET request.
-
Paste the Public Connection URL and change
wss
tohttps
. -
Add
/airline_10
to the end of the URL. Your URL should look similar tohttps://123456789.apps.capella.com:4984/travel-sample-appservice.inventory.airline/airline_10
. -
Select Basic Authentication.
-
Enter the username and password for the App User you created.
-
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:
-
Go to App Services and select an App Service.
-
Go to App Endpoints and select travel-sample-appservice.
-
Go to Connect.
-
Next to the Public Connection field, click Copy.
-
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:
-
Go to App Services and select an App Service.
-
Go to App Endpoints and click travel-sample-appservice.
-
Go to Connect.
-
Under Allowed IP Addresses, click Go to Allowed IP Addresses.
-
Click Add Allowed IP Address.
-
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 cluster.
-
Enter an IP address or IP address range in CIDR notation in the Allowed IP / CIDR Block field.
-
-
Click Add Allowed IP.
-
Go to App Endpoints and click travel-sample-appservice.
-
Go to Connect.
-
Under Admin Credentials, click Go to Admin Credentials for App Services.
-
Click Create Admin Credential.
-
In the Create Admin Credential page, do the following:
-
In the Username field, enter
admin
. -
In the Password field, enter a password for the admin credential.
-
Click Create Admin Credential.
-
You cannot change the Username and Password after creating the 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:
-
Go to App Services and select an App Service.
-
Go to App Endpoints and click travel-sample-appservice.
-
Go to Connect.
-
Next to the Admin Connection field, click Copy.
-
In your REST client, create a GET request.
-
Paste the Admin Connection URL.
-
Add
/_user/
to the end of the URL. Your URL should look similar tohttps://123456789.apps.capella.com:4985/travel-sample-appservice/_user/
. -
Select Basic Authentication.
-
Enter the admin credential you created.
-
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:
-
In your REST client, create a POST request.
-
Paste the Admin Connection URL.
-
Add
/_user/
to the end of the URL. Your URL should look similar tohttps://123456789.apps.capella.com:4985/travel-sample-appservice/_user/
. -
Select Basic Authentication.
-
Enter the admin credential you created.
-
In the request body, add the following JSON code:
{ "name": "demo2@example.com", "password": "password", "admin_channels": [ "string" ], "disabled": false }
-
Send the POST request.
-
Go to App Services and select an App Service.
-
Go to App Endpoints and click travel-sample-appservice.
-
Go to
. -
In the Capella UI, return to the App Endpoints page.
-
Click travel-sample-appservice.
-
Go to
.
The POST request adds the new user demo2@example.com.
For more information about the Admin REST API, see Admin REST API.