Message:

Subscribe rss
Blog categories
All | Backendless features
Feature 16: Data retrieval API – how to load objects from an mBaaS storage
January 23, 2015 by markpiller
Spread the love

Loading data objects from the Backendless persistent storage is a fundamental operation a large majority of the online/mobile applications require. Backendless data retrieval API is simple, yet very powerful. As you will learn in the course of this series, the API provides the following capabilities:

All the features listed above are based on the core data loading API. Consider the example below, but make sure your Backendless backend contains some data. The example in this post (as all the other related posts highlighting the data retrieval features) will use the Restaurant To-Go App schema. You can populate the backend with data using the import feature:

  1. Download the file from the URL below:
    https://backendless.com/documentation/samples/restaraunt-app-tables-with-data.zip
  2. Follow the instructions on how to import schema/data into a Backendless application. You will need to import the file from step above.

The sample code below will be fetching data from the following table:
restaurants table - Feature 16: Data retrieval API - how to load objects from an mBaaS storage

Additionally, the example below will be using the code generated by Backendless.  To get the code make sure to follow the instructions describing how to generate client-side code based on the backend’s database schema.

Asynchronous API (applies to Android and plain Java):

Synchronous API (Applies only to Java):

Complete project source code is available in the Backendless GitHub repository.

Restaurant class:

Asynchronous API:

Synchronous API:

Complete project source code is available in the Backendless GitHub repository.

Restaurant class:

Asynchronous API:

Synchronous API:

Asynchronous API:

Synchronous API:

 

The example demonstrates the usage of the data loading API in its most basic form. The highlighted lines show the actual API. It returns a collection of objects. Notice that the collection is strongly-typed – you do not need to perform any additional unmarshalling of data. Also, the same data object which is saved on the backend is automatically morphed into the client-side type. In other words the same restaurant object can arrive as a Java POJO to Android/Java application or an Objective-C or Swift object to an iOS app.

The code produces the following output:

As you can see, the example above prints out the names of the restaurants. The code implies that the results are paged (see the getCurrentPage call). We will be reviewing the paging feature in a future post.

Enjoy!

Share this post
Tweet about this on TwitterShare on FacebookGoogle+