A Quick Guide to Sending Push Notifications

Being able to send Push Notifications to users is one of the fundamental capability in an enterprise mobile app. Appery.io platform comes with Push Notifications component out-of-the-box and allows you quickly to send targeted messages to iOS and Android devices. In this blog post we will show the four ways to send a Push Notification message to a user:

  1. Push Notifications Console.
  2. Server Code Push Notifications API (server-side).
  3. Push Notification REST API.
  4. Customer Console.

Push Notifications Console

This first option is probably the simplest way to send a Push Notifications once you have installed an app on a device. Select device types, enter the message and send. The Push Notification message should arrive on the registered device instantly.

 

PN_console.png

Push Notifications console.

 

Continue reading

Quickly Invoke Lyft API from Appery.io Server Code

Appery.io Server Code makes it simple to invoke any external REST API. In this blog post, I will show you how to invoke Lyft API. I will use the Ride Types API to show what types of cars are available based on a location – latitude and longitude. Lyft is a ride sharing company that’s disrupting car ownership and moving forward with self-driving cars initiative.

Let’s start with the tutorial.

The first step is to perform authentication to get an access token to invoke any Lyft API. As the Ride Types API doesn’t use any user data, you can use client credentials for authentication. The script to get an access token looks like this:

var url = "https://api.lyft.com/oauth/token";
var client_id = "<client_id>";
var client_secret = "<client_secret>";

var XHRResponse = XHR2.send("POST", url, {
  "body": {
    "grant_type": "client_credentials",
    "scope": "public"
  },
  "headers": {
    "Content-Type": "application/json",
    "Authorization": "Basic "+encodeBase64(client_id+":"+client_secret)
  }
});
Apperyio.response.success(XHRResponse.body, "application/json");

The response will look like this:

{
   "expires_in": 86400,
   "token_type": "Bearer",
   "scope": "public",
   "access_token": "<access_token>"
}

Once you have the access_token, it is as simple to invoke the Ride Types API:

var url = "https://api.lyft.com/v1/ridetypes"; // REST API URL

var XHRResponse = XHR2.send("GET", url, {
  "parameters": {
    "lat": "37.7833", // San Francisco
    "lng": "-122.4167"
  },
  "headers": {
    "Authorization": "Bearer " + &lt;access_token&gt;
  }
});
Apperyio.response.success(XHRResponse.body, "application/json");

The response looks like this, it shows the type of rides available in San Francisco: Lyft, Lyft Line, and Lyft Plus.

{
	"ride_types": [{
		"ride_type": "lyft_line",
		"pricing_details": {
			"cost_per_minute": 23,
			"base_charge": 200,
			"currency": "USD",
			"trust_and_service": 175,
			"cost_per_mile": 115,
			"cancel_penalty_amount": 500,
			"cost_minimum": 475
		},
		"image_url": "https://s3.amazonaws.com/api.lyft.com/assets/car_standard.png",
		"seats": 2,
		"display_name": "Lyft Line"
	}, {
		"display_name": "Lyft",
		"image_url": "https://s3.amazonaws.com/api.lyft.com/assets/car_standard.png",
		"pricing_details": {
			"cost_minimum": 500,
			"cost_per_minute": 23,
			"base_charge": 200,
			"currency": "USD",
			"trust_and_service": 175,
			"cost_per_mile": 115,
			"cancel_penalty_amount": 500
		},
		"ride_type": "lyft",
		"seats": 4
	}, {
		"display_name": "Lyft Plus",
		"ride_type": "lyft_plus",
		"image_url": "https://s3.amazonaws.com/api.lyft.com/assets/car_plus.png",
		"seats": 6,
		"pricing_details": {
			"currency": "USD",
			"cost_minimum": 700,
			"cost_per_mile": 200,
			"trust_and_service": 175,
			"cancel_penalty_amount": 500,
			"cost_per_minute": 30,
			"base_charge": 300
		}
	}]
}

Want to learn how to build mobile apps fast? Check out the Appery.io YouTube channel for videos.

Video Tutorial: How to Build and Test a Complete Mobile App with API Backend

This video shows how to build and test a complete Ionic app with an API backend. The tutorial starts by showing how to create an app backend with API Express by connecting to an external REST API. Then, the tutorial shows how to build an Ionic app and import the backend service into the app. The tutorial also shows how to make a small change to the generated code. The tutorial then shows how to test the app in the browser and also on a device using the Appery.io Tester app. Lastly, the tutorial shows where to build a binary file for iOS or Android for submission to an app store.

Check out other videos on how to build mobile apps fast.

Learn How to Perform Basic Database Operations: Create, Read, Update, and Delete

The Appery.io Backend Services consists of the following components:

  • Database – for storing any app data.
  • Server Code – for writing server-side app logic using JavaScript.
  • 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.

One of the most common questions we get is how to work with the database, how to create, edit and delete data. This makes sense as virtually any mobile app needs to store data in a database and perform these basic operations. To access the database, we are going to use Server Code script. Server Code allows writing app logic using JavaScript which will be executed on the server. For example, a script can access the database, send a Push Notification message, sort data and invoke an external REST API. We will start with the most basic operation: how to read data from the database.

The database collection used in this post looks like this:

crud_collection

Database collection.

This can be data collected from a form inside an app – a form that collects information about the user.

Reading Data

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");
Apperyio.response.success(result, "application/json");

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:

 

crud_test

Script testing.

 

Reading data from a database collection is fast and simple. Next, we are going to save data into the database.

Continue reading

How to Build and Test an Ionic SMS App

This video shows how to build and test an Ionic SMS app using Nexmo API. The video tutorial first shows how to create a backend to invoke Nexmo API. Then the Ionic app is created which uses the backend. The app is then tested in the browser and on the device using the Appery.io Tester app. The video also shows how to build a binary file for Android and iOS.

Looking for more videos to help build mobile apps? Check out the Appery.io YouTube channel.

Video Tutorial: How to Build a REST API for a Custom SQL Query

This video shows how to use the SQL and Script components to build a Login service. The SQL component runs a custom SQL query to check if a user exists in a database. The Script component adds custom logic to check what the SQL component returned and defines the response (user found or user not found).

Looking for more videos on enterprise integration? Watch the API Express playlist.

Video: How to Build an Ionic App with an RSS Feed

This short video shows how to build an Ionic app that connects to an RSS feed. You can click on a link and navigate to the article. RSS feed used in this tutorial: http://feeds.gawker.com/lifehacker/full.

There are many more videos on the Appery.io YouTube channel to help you build mobile apps fast.

Video: Learn How to Build a Mobile App with External REST API

This short video shows how to build a complete app with an external REST API. This video covers:

  • Using API Express to connect to an external REST API. https://randomuser.me/ is used for the API.
  • Importing API Express service into the app (App Builder).
  • Designing the app UI (1 page).
  • Binding and using the service from the page.
  • Testing the app.

Looking for more videos? Visit the Appery.io YouTube channel for many more short videos.

Learn How to Connect Your App to an API Backend

This short video shows how to import backend services APIs into your app. Appery.io services consist of a cloud database, Server Code for custom app logic, and API Express for enterprise integration and service orchestration.

Our YouTube channel has many more short videos where you can learn how to build apps fast with Appery.io.

Moving App Logic to the Server: How to Save and Query an Appery.io Database from Server Code Script

The Appery.io Database provides storage for your mobile app data. You can store data such as users, orders, purchases, products or anything else. The Appery.io Database is a cloud NoSQL database and provides a very simple and elegant REST API to work with the database.

One of the most common cases for an enterprise mobile app is to create/save a new item/record and then redisplay the list in the app with the newly created item.

Accessing the database directly from the client is fine but requires two requests to the database.

  1. A request to save the new item/record into the database.
  2. Once the 1st request completes, on its success, a request to get the updated list to display in the app.

A better approach is to do both the create and list in a single request from the app. This is very simple to do from Appery.io Server Code script. The following script shows how to create a new record and then get the updated list:

var dbId = "cdaec951....d8";
var collectionName = "People"

var newName = request.get("name");
var newTitle = request.get("title");

// Save new object into the collection
Collection.createObject(dbId, collectionName, {
   "name": newName,
   "title": newTitle
});

// Retrieve updated data from the collection
var result = Collection.query(dbId, collectionName);
// Return the updated list (including the new object)
Apperyio.response.success(result, "application/json");

In this simple script you first create a new Person object (line 8) and then do another query to get the updated list of people (line 14). The script response returns the updated list of people. This script automatically has a REST API which is the invoked from the app.

What’s most important, there is only a single request from the app to the Server Code script. A single request is usually better than two requests. Also, you can add additional logic to the script without impacting the app. For example, you can send an email when a new person is added. Or, you can send  Push Notification when a new person is added. All this can be done without impacting the app. That’s nice.

If you want to learn more about Server Code, check out our YouTube channel Server Code playlist.