Getting your next mobile app connected with Azure Mobile Apps

New to Azure? Need a backend for your mobile app? Here here are key considerations and tips for start developing mobile apps with Azure Mobile Apps.

In a world of mobile-connected devices, one of the primary components for your app is a backend, which provides security, availability and scalability according to your requirements, audience and/or storage capabilities. Instead of doing everything on the user’s device, your app might choose to rely certain responsabilities like complex business processes and time-consuming tasks without compromising the user security and device’s memory.

Meet Azure Mobile Apps:

Azure Mobile Apps is a set of cloud services that allows you to quickly build and run mobile backends with a set of RESTful and OData services through a set of SDKs for connecting programming different stacks including JavaScript, C#, Objective-C, Swift, Java, Cordova and more, which provides a wide-open development board across web, hybrid and native platforms.

Azure Apps

This is extremely important for organizations moving from on-premises environments to cloud services and new app opportunities that require highly-available cloud solutions and common mobile features including:

Connection awareness and offline sync.

Handling device-disconnected situations is an important feature to prevent your apps to stop working and be useless for your users when your device is offline. Even better, resilent services allow applications to be aware of losing connectivity and sync with your backend when connection is back. There are some cloud products that support this feature including CouchBase’s Mobile, Google’s Firebase, Amazon’s Cognito and Azure as well.

With Azure Mobile Apps, you can take advantage of offline and sync features by having:

Note:
Azure Mobile Apps was previously known as Azure Mobile Services, which has been renamed these days for transitioning to Azure App Service. If you have already been using Azure Mobile Services we recommend you to take look on the transition notes here.

Getting started with Mobile and Azure.

In a nutshell, with Azure Mobile Apps you can create mobile backends in two ways:

Here the steps for start using Easy Tables and easily set up a mobile backend in minutes:

1. Setup the Mobile App from Azure portal.

From Azure Portal you can go to New -> Web + Mobile -> Mobile App to start creating your mobile backend and choose the public Azure URL for it:

1.setup

2. Define your Easy Tables schema.

From the Azure portal you can setup your table schema quickly and define the fields that you need to store:

2.tableSchema

By default, the No-code APIs relies on its own in-built DB, which you can eventually swap into any other SQL/NoSQL persistance of your choice supported by Azure.

3. Start using the REST endpoint.

You can bring your favorite REST debugging tool for testing your no-code API and start using the GET, PUT, UPDATE and DELETE verbs over it.

3.PostJSON

Make sure to include the ZUMO-API-VERSION header with the proper version (2.0.0) to the REST debugging tool of your choice (which is Postman in this case).

Tips for connecting it to your mobile app

  1. Bring the proper SDK for your platform (Swift, Java, Cordova, Xamarin)
  2. Configure your client instance (URL) in your app and map your DTOs (Data-Transfer Objects)
  3. Start using it

- Bring the SDK for your mobile app.

package

- Configuring your app and DTOs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
namespace YourNextMobileApp
{
using Microsoft.WindowsAzure.MobileServices;
using Newtonsoft.Json;

public class Contact
{
[JsonProperty("Id")]
public string Id { get; set; }

[JsonProperty("Name")]
public string Name { get; set; }

[JsonProperty("Phone")]
public string Phone { get; set; }

[Version]
public string Version { get; set; }
}
}

- Tip: Abstract Mobile Mobile Apps with your own ICloudService to be used through your app.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public interface ICloudService
{
Repository<Contact> Contacts { get; }

void Initialize();
}

public class AzureCloudService : ICloudService
{
private IMobileServiceClient _client;

public Repository<Contact> Contacts { get; set; }


public void Initialize()
{
_client = new MobileServiceClient(APP.KEYS.BACKEND_URL);

Contacts = new Repository<Contact>(_client);
}
}

By abstracting your Azure implementation it gets easier for mocking and keep dependencies down through your app.

- Then the Repository implementation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
namespace YourNextMobileApp
{
using Microsoft.WindowsAzure.MobileServices;
using System.Collections.Generic;
using System.Threading.Tasks;
using System;

public class Repository<T>
where T : class
{
IMobileServiceClient _proxy;

protected IMobileServiceTable<T> Table { get; private set; }
protected Logger Logger { get; set; }

public Repository(IMobileServiceClient proxy)
{
_proxy = proxy;
Table = _proxy.GetTable<T>();

Logger = new Logger();
}

public async Task<IEnumerable<T>> Get()
{
var empty = new T[0];

try
{
return await Table.ToEnumerableAsync();
}
catch (Exception ex)
{
Logger.Trace(ex);
return empty;
}
}
}
}

Additional Repository instances can be added layer and keep it organized.

- Tip: Keeping your mobile app responsive with async calls

1
2
3
4
5
6
7
8
9
10
11
12
private async void FetchAsync()
{
var result = await Repository.Get();

if (result.Any())
{
foreach (Contact singleItem in result)
{
_observable.Add(new ContactViewModel (singleItem));
}
}
}

- Demo: Fetching the data (Android / Google Maps)

demo

Easy Tables vrs. Azure Mobile Apps - When to choose?

While Azure Easy Tables are quick and powerful, the underlying backend relies on a NodeJS implementation, which might not worry you about at least you want to extend it with JavaScript. Alternatively, you can provide your own C#-based Mobile backend on existing Azure SDK tooling and extend your API implementation as needed.

Here are some key considerations for choosing between Azure Easy Tables and Azure Mobile Apps with a .Net/NodeJS backend:

+ Pros of Easy Tables:

- Cons of Easy Tables:

In the other side, a fully Azure Mobile App backend allows you to bring additional logic layers that be extended with your own backend code with NodeJS / Asp.Net Core and host it on Azure.

+ Pros of Azure mobile-backend implementations:

- Cons of Azure mobile-backend implementations:

Wrapping up.

So far, we explored some of the basics of bringing Azure Mobile Services into your next mobile app. As we saw, you can start with Easy Tables in minutes as a way of setting up a mobile backend right out the door directly from the Azure Portal and start using the REST/OData endpoints directly from your app.

Also, we examined some of the scenarios when you might need or not your own coded backend, and some key considerations before transitioning from Easy Tables to a full Azure Mobile App backend in case you need it.

By using one or the other, you can take the Azure Mobile SDKs available to your development stack and start right the way with a lot features out-the-box for mobile apps including offline-sync and social integrations.

Hopefully those tips can help you to take important features from your Azure box and help you to try or decide to use Azure for your next mobile app or not.

Happy coding!

Xamarin - Mobile apps with .Net and Azure