Tuesday, January 12, 2021

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 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,

  1. Log in to the Azure Portal.
  2. Click New-> Compute -> Function App.

    Azure Functions

  1. Enter all the required details and click Enter.

    Azure Functions

  1. Functions app will be provisioned within a few minutes.
  2. Click Function Apps->AzureFunctionsExamples (which you have created) -> Functions -> “+” to create new function.

    Azure Functions

  1. Click Custom Function.

    Azure Functions

  1. Select HTTP Trigger -> C#.

    Azure Functions

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

    Azure Functions

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

    Azure Functions

Test the function

  1. Click Get function URL and copy the URL.

    Azure Functions

    Azure Functions

  1. 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

    Azure Functions

  1. 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.

    Azure Functions

Result

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

No comments:

Post a Comment

No String Argument Constructor/Factory Method to Deserialize From String Value

  In this short article, we will cover in-depth the   JsonMappingException: no String-argument constructor/factory method to deserialize fro...