Azure Functions Docs

Function Recipes

Explore practical examples and common patterns for building robust and efficient Azure Functions.

Common Use Cases

HTTP Triggered API Endpoint

Learn how to create a simple RESTful API endpoint using HTTP triggers. Covers request handling, response generation, and parameter parsing.

View Recipe →

Scheduled Tasks (Timer Trigger)

Implement background jobs or recurring tasks using timer triggers. Ideal for data processing, cleanup, or scheduled notifications.

View Recipe →

Data Processing with Queue Storage

Build functions that process messages from an Azure Queue Storage. This is a fundamental pattern for decoupling services and handling asynchronous operations.

View Recipe →

Cosmos DB Integration

Connect your functions to Azure Cosmos DB for data persistence. This recipe covers creating, reading, updating, and deleting documents.

View Recipe →

Blob Storage File Handling

Develop functions that react to changes in Azure Blob Storage, such as uploading, downloading, or processing files.

View Recipe →

Advanced Patterns

Durable Functions for Orchestration

Discover how to use Durable Functions to orchestrate complex workflows involving multiple function calls, state management, and long-running processes.

View Recipe →

Event Grid Event Handling

Create functions that subscribe to and respond to events published by Azure Event Grid, enabling event-driven architectures.

View Recipe →

Cosmos DB Change Feed Processor

Leverage the Cosmos DB Change Feed to trigger functions in real-time as data is modified within your Cosmos DB containers.

View Recipe →

Example Snippets

Here are a few common code snippets you might find useful:

HTTP Trigger (Node.js)


import { AzureFunction, Context, HttpRequest } from "@azure/functions";

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
    context.log('HTTP trigger function processed a request.');
    const name = (req.query.name || (req.body && req.body.name));
    const responseMessage = name
        ? "Hello, " + name + "!"
        : "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.";

    context.res = {
        status: 200,
        body: responseMessage
    };
};

export default httpTrigger;
            

Timer Trigger (C#)


using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;

public static class TimerTriggerExample
{
    [FunctionName("TimerTriggerExample")]
    public static void Run([TimerTrigger("0 */5 * * * *")]TimerInfo myTimer, ILogger log)
    {
        log.LogInformation($"C# Timer trigger function executed at: {DateTime.Now}");
        // Your scheduled task logic here
    }
}
            

Queue Trigger (Python)


import logging
import azure.functions as func

def main(msg: func.QueueMessage) -> None:
    logging.info('Python queue trigger function processed a ' +
                 'message: %s',
                 msg.get_body().decode('utf-8'))
    # Process the message content