Today, applications need a back-end component to save data to a database, create logical flows, and many other situations. These components can be created using many different technologies. In this article, we will open the doors to the world of Azure serverless by examining how these back-end API components are created using the Azure Functions service with an example.
What is Azure Functions?
Azure Functions is a serverless (FaaS – Function as a Service) cloud service offered by Microsoft that allows you to run small pieces of code without concerned about the application infrastructure. With Azure Functions, the cloud infrastructure provides all the latest servers you need to use in an application running at scale.
Building a backend Web API using Azure Functions
In this demo, we will develop a Web API using HTTP trigger with Azure serverless architecture.
You can use this link to create a free Azure trial account.
After logging into the Azure portal, select create a new resource and let’s proceed by create a Function application.
While creating our application, we enter the following parameters. (Figure 2)
Resource Group: Name for the new resource group in which to create your function app.
Function App Name: Name that identifies your new function app. (Globally unique name)
Publish: Option to publish code files or a Docker container.
Runtime stack: I will develop the app with C# therefore I am choosing .NET Core
Version: Choose a runtime that supports your favorite function programming language. Choose .NET Core for C#
Region: Choose a region near you or near other services your functions access.
When we come to the hosting section, it will ask us to create a storage space or choose an existing one. I am moving forward by creating a new one again.
I am choosing Consumption (Serverless) as Plan Type.
After our application is created in a very short time, we go to our application by saying “Go to Resource”.
Then, we create a new function by clicking Functions from the menu on the left. Here you can also create a custom scenario yourself or proceed through sample scenarios. (Figure 4)
After selecting the HTTP Trigger, we give the name of the function we will create. We choose Anonymous as the Authorization Level.
After the function is created, all the necessary codes and settings are done automatically. Now we can perform our tests by making a small change on the code. I added a new parameter called “surname”.
Then, after saving our code, we call “Test / Run”. After entering the request body, we run our HTTP request by executing Run.
And we observe that our request works successfully with the 200 OK status code
I hope it has been a useful article, hope to see you.
Sreeram, P. K. (2018). Azure Serverless Computing Cookbook: Build and monitor Azure applications hosted on serverless architecture using Azure Functions, 2nd Edition. Packt Publishing.
M. (2020, January 16). Azure Functions Overview. Microsoft Docs. https://docs.microsoft.com/en-us/azure/azure-functions/functions-overview