How To Create A Simple Azure Function App Using C#

Azure Functions are used for executing a small piece of code or “functions” in a cloud and you will pay only for the time your code executes. You can use development language of your choice such as C#, F#, PHP, Java etc. Some of the key features of Functions are Choice of language, Pay-per-use pricing model, bring your own dependencies, integrated security, simplified integration, flexible development, and open-source. Please refer to Azure Functions for more details. In this article you will see how to create a simple Azure Function using C# that will run whenever an HTTP request is received.


Introduction

Azure Functions are used for executing a small piece of code or “functions” in a cloud and you pay only for the time your code executes. You can use development language of choice, such as C#, F#, PHP, Java etc. Some of the key features of Functions are - Choice of language, Pay-per-use pricing model, Bring in your own dependencies, Integrated security, Simplified integration, Flexible development, and Open-source. Please refer official page of Azure Functions for more details. In this article, you will see how to create a simple Azure Function using C# that will run whenever an HTTP request is received.


Create a simple Azure Function in the Azure portal,

  • Log in to the Azure Portal.

  • Click New-> Compute -> Function App.



  • Enter all the required details and click Enter.


  • Functions app will be provisioned within a few minutes.

  • Click Function Apps->AzureFunctionsExamples (which you have created) -> Functions -> “+” to create new function.


  • Click Custom Function.


  • Select HTTP Trigger -> C#.


  • Enter the name of the new function and click "Create".


  • The default code will be available to print Hello + query parameter “name” value.


Test the function

  • Click Get function URL and copy the URL.



  • Append “&name=<value>” to the copied function URL and enter into the browser. Function will return the results. For example https://azurefunctionsexamples.azurewebsites.net/api/HttpTriggerCSharpDemo?code=ko6560WiKCioJVUaxSV9GAlbWJ0iWBhyPgcpbbfhYFmQJPLaGqGa6Q==&name=Vijai Anand



  • Also, you could test it on the same page by entering the query parameter value and then by clicking Run. You could also trace the logs the output as shown in below screenshot.


Result

Thus, in this article, you saw how to create a simple Azure Function using C#.