In this article, We learn how to create and implement Azure Function App. I will show you how and just follow the steps clearly.

For more updates please do Subscribe via Email:

Overview

In this article we learn how Azure function app works . To create Azure Function app project please refer this link here. Azure function App is a serverless concept of cloud native design that allows a piece of code deployed and execute without any need of server infrastructure, web server, or any configurations. Azure functions can be written in multiple languages such as C#, Java, JavaScript, TypeScript, and Python.

Implementation

Let begin….

FunctionName

This is the name of your function but the default name it upon created is “Function1” but in my case I renamed is into “DemoFA”.

[FunctionName("Function1")]

This is the function name or method name of your FA endpoint API url.

In my case I rename it so its look like this.

And my URL function app endpoint is.

So now you can triggered your FA by using this endpoint url.

Method

Method is a kind of request in rest API to access or request it. example is “GET”, “POST” and ect.

By default the function app method created is set up by “GET”, “POST”. But you can modify it depend on the function app requirement.

As you can see the photo I added “PUT” request. So when I send a request using PUT method it will accept.

Http Request Parameter

There are many technique on how to pass a value using http request in Function. But we discuss only the two basic and must popular ways to pass a value in function.

  • First send value using Query function with specific parament name.
string name = req.Query["name"];
  • Next one is by the request body.
  string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            string name = data?.name;

Logs

There are many ways to put logs in your function app project. But we only the two basic, known, and mostly used in coding.

  • LogInformation – This is used to logs the information like success or any informative info during function is running.
  • LogError – This is also used to logs the error information.HTT

Http Response

Function App endpoint also has a http response depend on your project requirement same as the Rest API.

 [FunctionName("DemoFA")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", "put", Route = null)] HttpRequest req,
            ILogger log)
        {

            log.LogInformation("- LogInformation");
            log.LogError(" - LogError");


            //log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);

            name = String.IsNullOrEmpty(name)? data?.name: name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";



            return new OkObjectResult(responseMessage);
        }

As code above FA return a reponse value of string.

Test it out using postman and this is the result.

But you can make you FA with no response value like this.

or like this.

Hopefully you lean something new on how to create and implement in Azure function app.

Happy Learning..

Thank you for visiting my blog site. Hoping you learn more here. please feel free to comment and suggest if there is need to enhance and update. thank you.

Related Topics

Leave a Reply

Your email address will not be published. Required fields are marked *