Azure Functions Mobile Apps bindings

This article explains how to configure and code Azure Mobile Apps bindings in Azure Functions. Azure Functions supports input and output bindings for Mobile Apps.

The Mobile Apps input and output bindings let you read from and write to data tables in your mobile app.

This is reference information for Azure Functions developers. If you're new to Azure Functions, start with the following resources:

Mobile Apps input binding

The Mobile Apps input binding loads a record from a mobile table endpoint and passes it into your function. In a C# and F# functions, any changes made to the record are automatically sent back to the table when the function exits successfully.

The Mobile Apps input to a function uses the following JSON object in the bindings array of function.json:

{
    "name": "<Name of input parameter in function signature>",
    "type": "mobileTable",
    "tableName": "<Name of your mobile app's data table>",
    "id" : "<Id of the record to retrieve - see below>",
    "connection": "<Name of app setting that has your mobile app's URL - see below>",
    "apiKey": "<Name of app setting that has your mobile app's API key - see below>",
    "direction": "in"
}

Note the following:

  • id can be static, or it can be based on the trigger that invokes the function. For example, if you use a [queue trigger]() for your function, then "id": "{queueTrigger}" uses the string value of the queue message as the record ID to retrieve.
  • connection should contain the name of an app setting in your function app, which in turn contains the URL of your mobile app. The function uses this URL to construct the required REST operations against your mobile app. You [create an app setting in your function app]() that contains your mobile app's URL (which looks like http://<appname>.azurewebsites.net), then specify the name of the app setting in the connection property in your input binding.
  • You need to specify apiKey if you implement an API key in your Node.js mobile app backend, or implement an API key in your .NET mobile app backend. To do this, you [create an app setting in your function app]() that contains the API key, then add the apiKey property in your input binding with the name of the app setting.

    Important

    This API key must not be shared with your mobile app clients. It should only be distributed securely to service-side clients, like Azure Functions.

    Note

    Azure Functions stores your connection information and API keys as app settings so that they are not checked into your source control repository. This safeguards your sensitive information.

Input usage

This section shows you how to use your Mobile Apps input binding in your function code.

When the record with the specified table and record ID is found, it is passed into the named JObject parameter (or, in Node.js, it is passed into the context.bindings.<name> object). When the record is not found, the parameter is null.

In C# and F# functions, any changes you make to the input record (input parameter) is automatically sent back to the Mobile Apps table when the function exits successfully. In Node.js functions, use context.bindings.<name> to access the input record. You cannot modify a record in Node.js.

Input sample

Suppose you have the following function.json, that retrieves a Mobile App table record with the id of the queue trigger message:

{
"bindings": [
    {
    "name": "myQueueItem",
    "queueName": "myqueue-items",
    "connection":"",
    "type": "queueTrigger",
    "direction": "in"
    },
    {
        "name": "record",
        "type": "mobileTable",
        "tableName": "MyTable",
        "id" : "{queueTrigger}",
        "connection": "My_MobileApp_Url",
        "apiKey": "My_MobileApp_Key",
        "direction": "in"
    }
],
"disabled": false
}

See the language-specific sample that uses the input record from the binding. The C# and F# samples also modify the record's text property.

Input sample in C#

#r "Newtonsoft.Json"    
using Newtonsoft.Json.Linq;

public static void Run(string myQueueItem, JObject record)
{
    if (record != null)
    {
        record["Text"] = "This has changed.";
    }    
}

Input sample in Node.js

module.exports = function (context, myQueueItem) {    
    context.log(context.bindings.record);
    context.done();
};

Mobile Apps output binding

Use the Mobile Apps output binding to write a new record to a Mobile Apps table endpoint.

The Mobile Apps output for a function uses the following JSON object in the bindings array of function.json:

{
    "name": "<Name of output parameter in function signature>",
    "type": "mobileTable",
    "tableName": "<Name of your mobile app's data table>",
    "connection": "<Name of app setting that has your mobile app's URL - see below>",
    "apiKey": "<Name of app setting that has your mobile app's API key - see below>",
    "direction": "out"
}

Note the following:

  • connection should contain the name of an app setting in your function app, which in turn contains the URL of your mobile app. The function uses this URL to construct the required REST operations against your mobile app. You [create an app setting in your function app]() that contains your mobile app's URL (which looks like http://<appname>.azurewebsites.net), then specify the name of the app setting in the connection property in your input binding.
  • You need to specify apiKey if you implement an API key in your Node.js mobile app backend, or implement an API key in your .NET mobile app backend. To do this, you [create an app setting in your function app]() that contains the API key, then add the apiKey property in your input binding with the name of the app setting.

    Important

    This API key must not be shared with your mobile app clients. It should only be distributed securely to service-side clients, like Azure Functions.

    Note

    Azure Functions stores your connection information and API keys as app settings so that they are not checked into your source control repository. This safeguards your sensitive information.

Output usage

This section shows you how to use your Mobile Apps output binding in your function code.

In C# functions, use a named output parameter of type out object to access the output record. In Node.js functions, use context.bindings.<name> to access the output record.

Output sample

Suppose you have the following function.json, that defines a queue trigger and a Mobile Apps output:

{
"bindings": [
    {
    "name": "myQueueItem",
    "queueName": "myqueue-items",
    "connection":"",
    "type": "queueTrigger",
    "direction": "in"
    },
    {
    "name": "record",
    "type": "mobileTable",
    "tableName": "MyTable",
    "connection": "My_MobileApp_Url",
    "apiKey": "My_MobileApp_Key",
    "direction": "out"
    }
],
"disabled": false
}

See the language-specific sample that creates a record in the Mobile Apps table endpoint with the content of the queue message.

Output sample in C#

public static void Run(string myQueueItem, out object record)
{
    record = new {
        Text = $"I'm running in a C# function! {myQueueItem}"
    };
}

Output sample in Node.js

module.exports = function (context, myQueueItem) {

    context.bindings.record = {
        text : "I'm running in a Node function! Data: '" + myQueueItem + "'"
    }   

    context.done();
};

Next steps

For information about other bindings and triggers for Azure Functions, see Azure Functions triggers and bindings developer reference