HTTP Triggered Function
A basic Azure Function that responds to HTTP requests. Perfect for building simple web APIs or webhook endpoints.
View Details Download SampleExplore a curated collection of code samples demonstrating the power and versatility of Azure Functions for serverless computing. These examples cover a wide range of scenarios, from simple HTTP triggers to complex integrations with other Azure services.
A basic Azure Function that responds to HTTP requests. Perfect for building simple web APIs or webhook endpoints.
View Details Download SampleThis function automatically executes when a new blob is created or updated in Azure Blob Storage. Ideal for image processing, data transformation, or file validation.
View Details Download SampleProcesses messages from an Azure Queue Storage queue. Useful for asynchronous task processing, decoupling applications, and handling background jobs.
View Details Download SampleReacts to changes in an Azure Cosmos DB container. Enables real-time data processing and event-driven architectures with NoSQL databases.
View Details Download SampleProcesses events from Azure Event Hubs, a big data streaming platform. Essential for IoT data ingestion, real-time analytics, and telemetry processing.
View Details Download SampleThis sample demonstrates a fundamental Azure Function that can be triggered via HTTP requests. It shows how to handle incoming request data, process it, and return a response. This is the most common entry point for web-based serverless applications.
async function index(context, req) {
context.log('JavaScript 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."
: "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
};
}
This sample showcases how to create an Azure Function that automatically runs whenever a new file is uploaded to a specified Azure Blob Storage container. It's often used for post-processing, data validation, or generating thumbnails.
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Logging;
using System.IO;
public static class BlobTriggerFunction
{
[FunctionName("BlobTriggerCSharp")]
public static void Run(
[BlobTrigger("samples-workitems/{name}", Connection = "AzureWebJobsStorage")] Stream myBlob,
string name,
ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
}
}
This sample demonstrates processing messages from an Azure Queue Storage queue. When a message is added to the queue, this function will be triggered to process it, making it suitable for asynchronous operations.
import logging
import azure.functions as func
def main(msg: func.QueueMessage) -> None:
logging.info('Python queue trigger function processed a queue item: %s',
msg.get_body().decode('utf-8'))
This sample shows how to create an Azure Function that reacts to changes in an Azure Cosmos DB document. It's powerful for implementing real-time data synchronization, auditing, or triggering downstream processes based on database events.
module.exports = async function (context, documents) {
context.log('JavaScript Cosmos DB trigger function was triggered by', documents.length, 'documents');
for (const doc of documents) {
context.log('Processing document:', doc);
// Add your processing logic here
}
};
This sample demonstrates processing events from Azure Event Hubs. It's designed for high-throughput scenarios, such as ingesting data from IoT devices, application logs, or clickstream data.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.EventHubs;
using Microsoft.Extensions.Logging;
public static class EventHubTriggerFunction
{
[FunctionName("EventHubTriggerCSharp")]
public static void Run(
[EventHubTrigger("samples-workitems", Connection = "EventHubConnectionString")] EventData[] events,
ILogger log)
{
log.LogInformation($"C# Event Hub trigger function executed at: {DateTime.Now}");
foreach (EventData eventData in events)
{
log.LogInformation($"Receieved event: {Encoding.UTF8.GetString(eventData.Body.ToArray())}");
}
}
}