Azure Functions

Some time ago Microsoft announced the Azure Functions. What it is exactly? So, Azure Functions are event driven functions which are executed on some occurrence of events but also can be used on-demand.

Couple of benefits of using those:

development and deployment is easier comparing to normal webapi or webapps

they allows developers to take action by connecting to data sources or messaging solutions and because of that making it easy to process and react to events

Azure functions are scale based and on demand – you pay only for the resources you consume

thanks to intuitive browser based user interface it’s easy to create scheduled or triggered piece of code implemented in a variety of programming languages

Getting started

To start using Azure Function first you’ve to login to Azure Functions portal and fallow the instructions. Once we are there and we’ve chosen an option we can write code, configure evens and monitor executions.

Now, lets try to write simple function using C#. In above dialog choose Webhook + API and C# as function language and click “Create the function”. After that you will be redirected to following code editor.

Let us try to insert a record in Azure SQL database with help of Azure Functions.

Start with adding new “project.json” file in which we will add all required nuget packages. You can simply copy and paste following JSON content:

1: {

2:"frameworks": {

3:"net46":{

4:"dependencies": {

5:"Dapper": "1.42.0",

6:"System.Data.SqlClient":"4.1.0",

7:"Microsoft.WindowsAzure.ConfigurationManager":"3.2.1"

8: }

9: }

10: }

11: }

Here it how it should looks like:

In next step we have to configure your azure sql database connection string with this function app. For that click on Function app settings at the bottom of the functionapp as shown below:

Once connection has been successfully added copy the connection string name (typically MS_TableConnectionString), close the views and navigate back to your function.

Now lets click on our HttpTrigger function, copy the below piece of code and paste it back into Azure Functions C# code editor (change table name and other settings as you need).