The Appery.io Backend Services consists of the following components:
- Database – for storing any app data.
- API Express – integrating with external systems and APIs.
- Push Notifications – sending push messages to devices.
- Web Hosting – publishing and hosting mobile web apps.
In this post, we will show you how a Server Code script integrates with the Database.
The database collection used in this post looks like this:
This can be data collected from a form inside an app – a form that collects information about the user.
Server Code script has out-of-the-box API to access the database to perform all the basic operations. The following script reads all objects from the above collection.
var dbApiKey = "fe7c124b-f7c5-4764-9274-173b56a97102";
var result = Collection.query(dbApiKey, "Data");
One line 2, the script retrieves all the data.
One line 3, the script response is set. A Server Code script is invoked as a REST API. The code on this line defines the API response.
A script can be quickly tested from the Run tab where you can see the JSON data:
Reading data from a database collection is fast and simple. Next, we are going to save data into the database.