Introduction
Azure Functions is a solution for easily running small pieces of code in the cloud. We can create, execute, and test our custom logic function without creating a VM or web applications and also without needing to install any software or infrastructure to run the function. In this article, you will learn about creating and testing Azure Functions using Azure Portal.
Steps to create Azure Functions
Step 1
Navigate to https://functions.azure.com and click on “Login to your account".
Step 2
We should be following two ways to create Azure Functions -
- Navigate to https://functions.azure.com and provide Azure Functions details to create the Azure Functions.
- Navigate to https://portal.azure.com, click on "New" from Azure portal > Web + Mobile >click on see All or Search > Function App.
Step 3 Create Azure Functions App
Provide the Functions app name and fill in the following details for creating new Functions.
- App Name – Provide your Unique functions name
- Subscriptions – Select your subscription Free or any type
- Resource Group -create or select existing resource group name.
- Hosting Plan – You can Select default hosting plan as consumption plan, you have to pay only for the time functions code runs.
- Location – Select Your nearest location (eg. South Central US).
- Storage Account – You can Select or existing storage account.
Step 4
Click on "Create" and wait for a few minutes to deploy the new Azure Function app. Expand your new function app and click the + button next to Functions.
Step 5
After clicking on + button, you will get the following screen. Select WebHook + API, choose a language for your function and click on "Create this function".
Step 6 Azure Functions Editor
The .csx file format allows you to write a C# function. Include any assembly references and namespaces at the beginning of the file as usual in C# and write your logic in Run method, just like below.
Step 7 Run and Test Azure Functions
You can provide JSON string like the following in the request body and click on the "Run" button for testing the Azure Functions.
Testing in Web Browser
The web browser is a simple way to trigger functions via HTTP. You can use a browser for GET requests that do not require a body payload and uses only query string parameters.
To test the function that we defined earlier, copy the Function URL from the Azure Functions portal like below.
Append the name parameter to the query string. Use an actual name for the <Enter a name here> placeholder.
https://<Your Function App>.azurewebsites.net/api/<Your Function Name>?code=<your access code>&name=<Enter a name here>, Paste the URL into your browser, and you should get a response similar to the following.
Related Article
- Getting Started with Azure Functions Using Azure Free Trial Account
Summary
In this article, you learned how to create and test Azure Functions in Azure Portal. If you have any questions/ feedback/ issues, please write in the comment box.