Azure App Configuration for Mobile Apps
Microsoft’s Azure suite of services includes a wide array of tools to help with the development of applications. If your organization uses that suite of services, you might consider using App Configuration as part of your toolkit. This will allow you to provide key/value pairs of data that are easily updated via a dashboard, rather than writing a custom API to return this kind of lightweight data.
This guide will lead you through the process of setting up Azure App Configuration in your existing account. Setting up a free Azure account is easy and straightforward, and I will presume you have this in place either as a test account for yourself, or as a part of your organization’s IT infrastructure.
After detailing how to set up the account, I’ll provide a sample Postman client in Javascript, and provide a Swift implementation as well.
Configuring your Azure instance
I won’t step you through creating an Azure account; it’s really quite straightforward to do initial account creation.
From your Azure developer portal, select “Create a resource”. From here, either browse or type in “App Configuration” to start creating the service.
After selecting “Create” on this service, you’ll be asked to make some basic setup decisions, such as which subscription to use (hint: use the default unless you know about multiple subscriptions), the resource group (this can tie a set of resources together, but is not necessary for setting up a single resource like this service), the name of your configuration instance, its location, and the price level. The free tier allows 1,000 calls per day, whereas a standard configuration includes 20,000 calls per hour. This is a perfect prototyping/release set of service levels.
Most of the time, you’re going to want to connect directly to this service from whatever app you’re building. (If not, you probably want to look into simpler key/value stores and a custom API.) To enable remote communication from mobile apps, you’ll want to enable public access to this API. Please note that even with public access, you’ll still be providing authorization in your app to use the API.
After setting up the basics and networking, you can select “Review + create” to verify that the configuration is acceptable, and your service will be deployed within a few moments.
When your configuration is done deploying, you’re almost ready to integrate this service into your app.
First, you’ll need to generate some read-only keys for the app. Ensure that you’re not creating read-write keys, as this could lead to your app configuration being modified by a bad actor. Select “Access Keys” from the left column, and create a new set of keys. In a secure location, make note of your endpoint, primary key, and id.
Finally, generate some key/value pairs inside the “Configuration Explorer” dialog. This is the last step in the road to use the Azure App Configuration service!
Reference Client Implementation: Postman / JavaScript
I enjoy setting up Postman collections for any service I’ll be interacting with, especially for services with more advanced configuration requirements. A simple cURL is great if there’s not much configuration needed, but once you go beyond a static header parameter it becomes unwieldy.
To build out a reference implementation, start by creating a new collection in Postman and set up some variables on that collection. You’ll want variables for the endpoint, the key, and the credential.
Once you’ve set the variables on the collection, you’ll create a simple GET request within that collection. The URL you’ll use for this request is {{endpoint}}/kv?api-version=1 , and the endpoint variable will be pulled in to provide a base URL. This URL will fetch all key/value pairs in the storage; once you’ve got this functional, you can absolutely simplify your own app implementation to only fetch a single key/value pair at a time.
Now that the request has been created, you’ll want to configure the pre-request script on this request. The script below will use the above variables to prepare the headers as needed.
When you run this script, you should see the values appear in the JSON response object, as shown below:
And now, you’ve retrieved the values set up in your Azure App Configuration dashboard! Check the items
array for each of the key / value pairs, and use them as needed.
Reference Client Implementation: Swift
The reference JavaScript implementation is great, but what would be even more helpful is a platform-specific implementation. We’ve got you covered for this; the AzureAppConfiguration-Swift project on GitHub contains a full-featured client with Swift Package Manager integration provided. Add it to Xcode, and you’re good to go! Once you have this in place, you’ll be able to create a truly simple client on iOS, with just a handful of lines of code:
This not only prepares your request, but also decodes the response into a simple dictionary of key/value pairs.
What are you going to use Azure App Configuration for in your mobile apps? Go ahead and leave a comment below, and continue the discussion!