Serverless Computing is Platform as a Service (PaaS) in Cloud Services. It allows us to deploy and manage individual code functions without a need to deploy and manage on the individual Virtual Machine (VM). Azure Functions is a serverless compute service that runs our code on-demand without needing to host it on the server and managing infrastructure. Azure Functions can be trigger by a variety of events. It allows us to write code in various languages, such as C#, F#, Node.js, Java, or PHP.

Glimpse of Post

Prerequisite

What is Webhooks?

How can we create Azure Functions in Azure portal?

Build Functions in Visual Studio:

using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace HttpTriggerFunctionApp
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            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 = name ?? data?.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);
        }
    }
}

Build Functions in VS code:

{
  "profiles": {
    "Functions": {
      "commandName": "Project",
      "commandLineArgs": "--port 7131",
      "launchBrowser": false
    }
  }
}

Conclusion

Next post will Concentrate on Azure Core Concepts and Services.

Surround yourself with people who challenge you, teach you, and push you to be your best self

Bill Gates

Leave a Reply

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


The reCAPTCHA verification period has expired. Please reload the page.