Azure Serverless Tutorials

Explore the world of serverless computing on Azure. Build scalable, event-driven applications without managing infrastructure.

Key Serverless Concepts on Azure

Serverless computing allows you to run your code without provisioning or managing servers. Azure offers a comprehensive suite of serverless services:

Example: A Simple HTTP-Triggered Azure Function

Here's a basic example of an Azure Function written in C# that responds to an HTTP request:

using System.IO;
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 AzureFunctions
{
    public static class HelloWorldFunction
    {
        [FunctionName("HelloWorld")]
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Function, "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)
                ? "Hello, World! Please pass a name on the query string or in the request body."
                : $"Hello, {name}!";

            return new OkObjectResult(responseMessage);
        }
    }
}
        

To learn more about deploying and running this function, please refer to the Build Your First Azure Function tutorial.