Appery.io

The Appery.io Developer Hub

Welcome to the Apperyio developer hub. You'll find comprehensive guides and documentation to help you start working with apperyio as quickly as possible, as well as support if you get stuck. Let's jump right in!

Guides    

Building a Notes App with Offline Support - Basic old

A tutorial to build an app with offline support.

Introduction

The tutorial provides step by step instructions that will walk you through the process of developing an application with offline capabilities. You will also learn how simple it is to use the Appery.io App Client to add powerful caching functionality to your apps.

The tutorial is divided into two parts: basic (part 1) and advanced (part 2). You should complete the basic tutorial first and then move to advanced tutorial. The advanced tutorial starts where the basic tutorial ended.

Target Audience

This tutorial is for advanced developers who have prior experience building apps with Appery.io.

Tutorial Format

The tutorial is organized in the following way:

  • Each chapter (section) describes one particular feature. At the end of each section you will find a link to the archive with the backup of the project, so you can start using the guide at any point without having to complete the previous steps of the tutorial.
  • The only prerequisite is to import the backup from the previous section.
  • At the end of each section, you will find more resources that will provide additional details about Appery.io features and the Client SDK.
  • Each Appery.io Client SDK method mentioned in the guide will be linked to the corresponding section of the SDK reference.

App You are Building

This tutorial will walk you through the process of creating a Notebook mobile app. The key features of the app:

  • Authentication.
  • Ability to work without internet connection with synchronization.
  • Conflicts resolving in case of failed synchronization.

Step 1: Creating a Database

The first step is to create the database where the notes will be stored.

  1. Create a new Appery.io database with Name : ApperyNoteDB.
  2. Create a collection with Name: Notes.
  3. Add a column with Name: content and type : String.
  4. Add a column with Name: deleted and type : Boolean.
  5. Fill the first row with a content equal to note1.

Download and Resources

Step 2: Creating Database Connection

To create a database connection in API Express which will refer to Appery.io database:

  1. Go to API Express > Create new DB connection.
  2. Create a database connection with:
    • Name : ApperyNoteDBConnection
    • Connection type : Appery.io database
    • Database name : ApperyNoteDB
  3. You don’t need to enter a username or password.
  4. Make sure that the connection is successful, click Test.

Download and Resources

Step 3: Creating API Express Project

To create an API Express project and services for Notes collections:

  1. Create an API Express project with the name ApperyNoteProject:
    • Create a Service group (click new service). Name it notes.
    • Select Generate REST API.
    • Select the ApperyNoteDBConnection Database connection.
    • Select the Notes table.
    • Check Data Synchronization checkbox
    • Check Deleted for deleted field
    • Click Save.
  2. You can click the Test link to open the test page and invoke services from the just created Service group.

Download and Resources

  • Download API Express project backup file from this step.

Step 4: Creating an Ionic App

To create a new Ionic app:

  1. Navigate to Apps (App Builder), click Create new app.
  2. Create a new application:
    • Name it ApperyNote.
    • Specify the Ionic Type.

Download and Resources

  • Download Ionic app backup file in this step.

Step 5: Generating Services to Connect to the Database

Once you have an app created, the next step is to generate services for the database to fetch and save data. To generate services which perform basic operations in the app:

  1. Click CREATE NEW and select API Express Generator.
  2. Select Appery.io as the host.
  3. Next, select the ApperyNoteProject project.
  4. Generate generic services for notes service (press generate) and name them NoteService.
  5. Press the Refresh button to refresh the App Builder.

Download and Resources

  • Download Ionic app backup file from this step.

Step 6: Creating the Notes Page

To create a page which shows notes from collection Notes:

  1. Rename Screen1 to Notes.
  2. Open Routing.
  3. Rename the route name Screen1 to Notes.
  4. On the Notes page, click SCOPE and add a new function loadData:
Apperyio.get("NoteService_find")({}).then( 
    function(success) {
        $scope.notes = success;
        $scope.$apply();
    },
    function(error) {
        console.log(error);
    },
    function(notify) {
        console.log(notify);
    });
  1. Open the init function (click edit) and modify it to:
$scope.loadData();
  1. In DESIGN view, add a List component to the Notes page.
    • Remove two last items from the List.
    • Add the ng-repeat directive for the ListItem and define it as note in notes.
    • Set the Item text to:
{{note.content}}.
  1. Press refresh (CTRL + F5) button several times with open network tab of browser. To notice how many times application loads the same data.
    Modify init function.
Apperyio.get("Notes_fetch")({}).then( 
    function(success) {
        $scope.loadData();
    },
    function(error) {
        console.log(error);
    },
    function(notify) {
    });
  1. Update loadData function
Apperyio.get("Notes_find")({"cached": true}).then( 
    function(success) {
        $scope.notes = success;
        $scope.$apply();
    },
    function(error) {
        console.log(error);
    },
    function(notify) {
    });
  1. Press refresh button several times. To notice that response of fetch operation is empty.
  2. Add in database new record with content: note2 .
  3. Pay attention that response of fetch operation contains only one record with content: note2. Application load only changed data

Tip

To test your app add another note to the Notes collect and click TEST in App Builder.

Result in This Step

Your app now displays records from the database.

Download and Resources

  • Download Ionic app backup file from this step.

Step 7: Creating the Note Page

The Notes pages displays all the notes from the database. The new Note page you will create in this step will allow to add a new note and save it into the database.

To create the page:

  1. Add a Button to the top of the Notes page. The button will forward the user to the Note page (this page will be created in step 3).
    • Set the Text property to Add.
    • Set thenavigate-to property to Note .
  2. Now, create a new page and name it Note. The page will display note information.
  3. Add a Button to the page. This Back button will return a user to the Notes page without saving a note.
    • Text : Back.
    • Add back-button property.
  4. Add another Button . This Save Button will return a user to the Notes page with saving a note.
    • Set the Text to Save and ng-click to save()
  5. Add an Input with ng-model set to content.
  6. Add isNew function
return Apperyio.get("$routeParams")._id == ":_id";
  1. Add getNoteId function
return Apperyio.get("$routeParams")._id;
    1. Modify init function.
if (!$scope.isNew()) {
        Apperyio.get("Notes_get")({"_id": $scope.getNoteId(), "cached": true}).then(
        function(success){ 
            $scope.content = success.content;
            $scope.$apply();
        },
        function(error){
            console.log(error);
        },
        function(notify){ 
        });
}
  1. Add a scope function, name it save.
var operation;
var requestObject = {"content": $scope.content};

if ($scope.isNew()) {
    operation = Apperyio.get("Notes_create"); 
} else {
    operation = Apperyio.get("Notes_update");
    requestObject._id = $scope.getNoteId();
}

operation(requestObject).then( 
        function(success) {
            Apperyio.navigateTo("Notes");
            $scope.$apply();
        },
        function(error) {
            console.log(error);
        },
        function(notify) {
  
        });

Result in This Step

The app now displays and adds records.

Download and Resources

  • Download Ionic app backup file from this step.

Step 8: Editing a Note

Now you can extend the app to allow editing existing notes.

  1. On the Notes page, select the List Item in List.
  2. Add ng-click directive and define it as edit(note._id).
  3. Add a scope function, name it edit and pass _id for its Arguments. Then, insert this code:
Apperyio.navigateTo("Note", {"_id": _id});
  1. Open Routing and update the path of the Note route to /Note.html/:_id.
  2. Select the List Item of the List component.
  3. Press the + button.
  4. Select Button.
  5. Remove the text from the button.
  6. Specify Icon of the button as ion-trash-b.
  7. Specify ng-click: remove(note._id, $event).
  8. Add a new scope function remove with arguments : ._id, $event.
Apperyio.get("Notes_delete")({
    "_id": _id
}).then(
    function(success) {
        $scope.loadData();
    },
    function(error) {
        console.log(error);
    },
    function(notify) {
    });
$event.stopPropagation();

Download and Resources

  • Download Ionic app backup file from this step.

Step 9: Adding Security

To secure the Notes collection and API Express project ApperyNoteProject and to add Login page to the NoteApp:

  1. Open Appery.io Databases ApperyNoteDB.
  2. Open Collection Notes.
  3. Open Security and permissions.
  4. Enable Secure collection and save.
  5. Open Users collection.
  6. Add two users:
    • Username user1 password pass1.
    • Username user2 password pass2.
      7.Open Change default ACL of Notes collection.
  7. Specify default value @Creator.
  8. In the top navigation bar click Resources.
  9. Open Security sub-tab.
  10. Add a new security provider:
    • Name it ApperyNoteSecurity.
    • Provider type Appery.io Database Security.
    • Appery.io database ApperyNoteDB.
    • Test and save it.
      12.Open API Express and then ApperyNoteProject.
  11. Open the Settings tab.
  12. Enable the Secure REST API option.
  13. Specify security provider as ApperyNoteSecurity.
  14. Open Apps and select the ApperyNote app.
  15. Add a new page, call it Login.
  16. Add an Input component:
    • Placeholder : Username.
    • ng-model : username .
    • Add another Input component:
    • Set Placeholder : Password.
    • Define ng-model as password.
    • Select Type : **password.
    • Add a button:
    • Text : Login.
    • ng-click : login().
    • Add a scope function login:
Apperyio.get("AppClientLogin")({
    username: $scope.username,
    password: $scope.password
}).then(
    function(success) {
        Apperyio.navigateTo("Notes");
        $scope.$apply();
    },
    function(error) {
        Apperyio.get("$ionicPopup").alert({
            title: 'Authentication error',
            template: "Username or password is incorrect"
        });
    },
    function(notify) {
        console.log(notify);
    });
  1. Open Routing.
  2. Select Login as default Route.

Download and Resources

  • Download Ionic app backup file from this step.

Building a Notes App with Offline Support - Basic old


A tutorial to build an app with offline support.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.