May, 2018
Backendless Marketplace is a specialized store for backend functionality. Our vision for the marketplace is to make it a community driven store for algorithms and API services. We also use the Marketplace for various Backendless”extenders” to help developers to increase the limits of the Backendless Cloud pricing plans. However, most importantly, the Marketplace can be used for sharing your API services with other developers.
By publishing your Cloud Code to the Marketplace, you can share your business logic components (e.g.: API services, event handlers and/or timers) with other Backendless developers. Once your Cloud Code is published, it becomes a Marketplace product and will be visible to all Backendless users (developers). In the upcoming releases, we’ll add a possibility to set a price for your products allowing you to charge a fee for every successful installation.
Today we will talk about the integration of Backendless into your AngularJS/TypeScript app. You will create a simple Address Book application where all the application data will be stored in the Backendless mobile backend. The main goal of this article is to provide step-by-step instructions and to show how to create an Angular application with Backendless mBaaS.
In this article, we will learn how to create QR codes with a custom Backendless API Service. For the sample code reviewed later in the article we will use Java and the ZXing library (https://github.com/zxing).
What is a QR code?
A QR code is a computer generated image with some information encoded in a graphical way. The information may include text, numbers, a URL – pretty much anything your app may need to represent in an encoded manner. What makes QR codes very useful is the encoded information can be then decoded by any device with a camera.
Below is an example of a QR code with the encoded link to Backendless Console: https://develop.backendless.com:
You can ‘read’ it with an iPhone (just use the standard camera app) or with an Android device if you install a QR Code reader app (check out Google Play, there is a ton of QR reading apps). Once the code is scanned, the encoded URL will be opened automatically in your web browser.
(For more details, click here: https://en.wikipedia.org/wiki/QR_code)
This series of tutorials was prepared by:
Ega Wachid Radiegtya
An Entrepreneur & App Developer
You will learn how to make your own LinkedIn clone on Android, using React Native, React Navigation, Redux and Backendless.
The following tutorial series is exactly what you’re looking for if:
Technology stack:
What you will learn:
By following the instructions in these articles, you’ll get the knowledge and skills required to build simple Android apps using Backendless mBaaS for your business logic.
Summary:
Part 1: Introduction
You will learn about the tools required for the task and how to set up the development environment to proceed.
Part 2: RN Setup
You will do your first steps to get some basic functions for your app.
Part 3: Backendless Setup
You will get familiar with Backendless and start building the server side logic for your app.
Part 4: RN+ Backendless; Building The App
You will finalize the visual part of your app and will get a functional Linkedin clone.
Backendless and Firebase, both being mobile BaaS platforms, are presenting different capabilities for mobile apps creation.
Here is a list of the Backendless features which either are not supported by Firebase or just exceed it in usability.
1 |
GET https://api.backendless.com/<appid>/<REST API key>/data/Movie?props=Sum(totalBoxOffice) |
1 2 3 4 5 6 |
[ { "sum": 14507795640, "___class": "Movie" } ] |
1 |
GET https://api.backendless.com/<app id>/<REST API key>/data/Orders?props=Sum(orderAmount)&groupBy=relatedCountry.countryName |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[ { "sum": 1324231, "countryName": "Italy", "___class": "Orders" }, { "sum": 5675675, "countryName": "France", "___class": "Orders" }, { "sum": 2342234, "countryName": "Ireland", "___class": "Orders" } ] |
1 |
GET https://api.backendless.com/<app id>/<REST API key>/data/Orders?props=Sum(orderAmount)&groupBy=relatedCountry.countryName&having=Sum(orderAmount)>10000 |
It is worthwhile to point out the following:
In this article, we’ll talk about Backendless publish-subscribe messaging. One of the frequent questions we receive is: ‘How to get messages long after they are published.’ The default mechanism in Backendless keeps messages in the published channel for a short period of time only (around a minute). This becomes a problem if subscriber needs to have access to the messages after that time period has passed. This article describes an approach for storing published messages in Backendless database in order to keep published messages accessible even when they are no longer present in a messaging channel.
Publish-subscribe is a Backendless messaging pattern. The main idea here is to exchange data between a publisher* and subscriber** within a messaging channel***.
* publisher – a program using the Publishing API to send messages to a channel.
** subscriber – a program using the Subscription API to receive messages from a channel.
*** channel – a logical intermediary “transporting” the messages.
In order to keep messages accessible for an infinite period of time – you can save messages into the Backendless database right after they were published. To accomplish this, we’ll need to combine Data service API and the afterPublish event handler which can be added to the Business Logic tab of your Backendless application.
Once it’s added, just download the afterPublish handler code from ‘Download’ menu (you can select JavaScript or Java). Then open the generated project in any IDE and add the code to store published messages in a Backendless data table.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
@Asset( "chatRoom" ) public class DefaultChannelEventHandler extends com.backendless.servercode.extension.MessagingExtender { @Override public void afterPublish( RunnerContext context, Object message, PublishOptions publishOptions, DeliveryOptions deliveryOptions, ExecutionResult<MessageStatus> result ) throws Exception { String publisher = publishOptions.getPublisherId(); String messageData = message.toString(); HashMap savedMessage = new HashMap(); savedMessage.put("publisher", publisher); savedMessage.put("messageData", messageData); Backendless.Data.of("ChatHistory").save(savedMessage); } } |
Alternatively, the
afterPublish event handler can be added and deployed to cloud without any coding at all using Codeless business logic. Here are the steps of how it can be done:
1. Add new Codeless event handler 2. When the handler is saved, Codeless designer will be opened. Add the following blocks to your Codeless logic. When done – click the ‘DEPLOY MODEL’ button.
Voila!
To avoid nulls, every message should be published with a not null value for publisherId :
1 2 3 4 5 6 7 |
public void publishMessage() { PublishOptions publishOptions = new PublishOptions(); publishOptions.setPublisherId("Jack"); String message = "Hello, this is my first message!"; Backendless.Messaging.publish("chatRoom", message, publishOptions); } |
For this scenario we’ll need to create a data table (Data > APP TABLES in your Backendless application) called ‘ChatHistory’ and define the following schema in it:
Once code for the handler is added, deploy the handler code to cloud using the following command in your IDE terminal:
./bin/Deploy.sh
Since the handler is deployed, every new message published to
chatRoom channel will be stored in a dedicated data table and will be accessible at any required moment by calling an API to retrieve data from a table:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
public void retrieveMessageHistory() { DataQueryBuilder dataQuery = DataQueryBuilder.create(); dataQuery.setOffset(0); dataQuery.setPageSize(100); dataQuery.setSortBy("created"); Backendless.Data.of("ChatHistory").find(dataQuery, new AsyncCallback<List<Map>>() { @Override public void handleResponse(List<Map> response) { for (Map message:response) System.out.println("Publisher: " + message.get("publisher") + "\n" + "Message data: " + message.get("messageData") + "\n" + "Posted at " + message.get("created")+ "\n\n"); } @Override public void handleFault(BackendlessFault fault) { System.out.println("Error retrieving message History: " + fault.getMessage()); } }); } |
You will receive the following output:
1 2 3 4 5 6 7 8 9 10 11 |
Publisher: Jack Message data: Hello, this is my first message! Posted at Mon May 21 19:53:13 EEST 2018 Publisher: Jack Message data: And this is the second one Posted at Mon May 21 19:53:40 EEST 2018 Publisher: Mike Message data: Hi, Jack! Posted at Mon May 21 19:54:13 EEST 2018 |