Note
Azure Mobile Apps bindings are only available to Azure Functions 1.x. They are not supported in Azure Functions 2.x and higher.
This article explains how to work with Azure Mobile Apps bindings in Azure Functions. Azure Functions supports input and output bindings for Mobile Apps.
The Mobile Apps bindings let you read and update data tables in mobile apps.
Packages - Functions 1.xMobile Apps bindings are provided in the Microsoft.Azure.WebJobs.Extensions.MobileApps NuGet package, version 1.x. Source code for the package is in the azure-webjobs-sdk-extensions GitHub repository.
The following table lists how to add support for output binding in each development environment.
Development environment To add support in Functions 1.x Local development: C# class library Install the package Local development: C# script, JavaScript, F# Automatic Portal development Automatic InputThe Mobile Apps input binding loads a record from a mobile table endpoint and passes it into your function. In C# and F# functions, any changes made to the record are automatically sent back to the table when the function exits successfully.
Input - exampleSee the language-specific example:
The following example shows a Mobile Apps input binding in a function.json file and a C# script function that uses the binding. The function is triggered by a queue message that has a record identifier. The function reads the specified record and modifies its Text
property.
Here's the binding data in the function.json file:
{
"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"
}
]
}
The configuration section explains these properties.
Here's the C# script code:
#r "Newtonsoft.Json"
using Newtonsoft.Json.Linq;
public static void Run(string myQueueItem, JObject record)
{
if (record != null)
{
record["Text"] = "This has changed.";
}
}
The following example shows a Mobile Apps input binding in a function.json file and a JavaScript function that uses the binding. The function is triggered by a queue message that has a record identifier. The function reads the specified record and modifies its Text
property.
Here's the binding data in the function.json file:
{
"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"
}
]
}
The configuration section explains these properties.
Here's the JavaScript code:
module.exports = async function (context, myQueueItem) {
context.log(context.bindings.record);
};
Input - attributes
In C# class libraries, use the MobileTable attribute.
For information about attribute properties that you can configure, see the following configuration section.
Input - configurationThe following table explains the binding configuration properties that you set in the function.json file and the MobileTable
attribute.
"id": "{queueTrigger}"
uses the string value of the queue message as the record ID to retrieve. connection Connection The name of an app setting that has the mobile app's URL. The function uses this URL to construct the required REST operations against your mobile app. Create an app setting in your function app that contains the mobile app's URL, then specify the name of the app setting in the connection
property in your input binding. The URL looks like https://<appname>.azurewebsites.net
. apiKey ApiKey The name of an app setting that has your mobile app's API key. Provide the API key if you implement an API key in your Node.js mobile app, or implement an API key in your .NET mobile app. To provide the key, 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.
When you're developing locally, add your application settings in the local.settings.json file in the Values
collection.
Important
Don't share the API key with your mobile app clients. It should only be distributed securely to service-side clients, like Azure Functions. 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 - usageIn C# functions, when the record with the specified ID is found, it is passed into the named JObject parameter. When the record is not found, the parameter value is null
.
In JavaScript functions, the record is passed into the context.bindings.<name>
object. When the record is not found, the parameter value is null
.
In C# and F# functions, any changes you make to the input record (input parameter) are automatically sent back to the table when the function exits successfully. You can't modify a record in JavaScript functions.
OutputUse the Mobile Apps output binding to write a new record to a Mobile Apps table.
Output - exampleThe following example shows a C# function that is triggered by a queue message and creates a record in a mobile app table.
[FunctionName("MobileAppsOutput")]
[return: MobileTable(ApiKeySetting = "MyMobileAppKey", TableName = "MyTable", MobileAppUriSetting = "MyMobileAppUri")]
public static object Run(
[QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string myQueueItem,
TraceWriter log)
{
return new { Text = $"I'm running in a C# function! {myQueueItem}" };
}
The following example shows a Mobile Apps output binding in a function.json file and a C# script function that uses the binding. The function is triggered by a queue message and creates a new record with hard-coded value for the Text
property.
Here's the binding data in the function.json file:
{
"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"
}
]
}
The configuration section explains these properties.
Here's the C# script code:
public static void Run(string myQueueItem, out object record)
{
record = new {
Text = $"I'm running in a C# function! {myQueueItem}"
};
}
The following example shows a Mobile Apps output binding in a function.json file and a JavaScript function that uses the binding. The function is triggered by a queue message and creates a new record with hard-coded value for the Text
property.
Here's the binding data in the function.json file:
{
"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
}
The configuration section explains these properties.
Here's the JavaScript code:
module.exports = async function (context, myQueueItem) {
context.bindings.record = {
text : "I'm running in a Node function! Data: '" + myQueueItem + "'"
}
};
Output - attributes
In C# class libraries, use the MobileTable attribute.
For information about attribute properties that you can configure, see Output - configuration. Here's a MobileTable
attribute example in a method signature:
[FunctionName("MobileAppsOutput")]
[return: MobileTable(ApiKeySetting = "MyMobileAppKey", TableName = "MyTable", MobileAppUriSetting = "MyMobileAppUri")]
public static object Run(
[QueueTrigger("myqueue-items", Connection = "AzureWebJobsStorage")] string myQueueItem,
TraceWriter log)
{
...
}
Output - configuration
The following table explains the binding configuration properties that you set in the function.json file and the MobileTable
attribute.
connection
property in your input binding. The URL looks like https://<appname>.azurewebsites.net
. apiKey ApiKeySetting The name of an app setting that has your mobile app's API key. Provide the API key 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 provide the key, 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.
When you're developing locally, add your application settings in the local.settings.json file in the Values
collection.
Important
Don't share the API key with your mobile app clients. It should only be distributed securely to service-side clients, like Azure Functions. 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 - usageIn C# script functions, use a named output parameter of type out object
to access the output record. In C# class libraries, the MobileTable
attribute can be used with any of the following types:
ICollector<T>
or IAsyncCollector<T>
, where T
is either JObject
or any type with a public string Id
property.out JObject
out T
or out T[]
, where T
is any Type with a public string Id
property.In Node.js functions, use context.bindings.<name>
to access the output record.
Learn more about Azure functions triggers and bindings
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4