Azure Serverless APIs

Explore practical sample projects for building robust serverless APIs on Azure.

Featured Serverless API Samples

Order Processing API with Azure Functions & Cosmos DB

A comprehensive example demonstrating how to build a RESTful API for processing customer orders using Azure Functions, Cosmos DB for data storage, and Azure API Management for security and throttling.

Azure Functions Cosmos DB API Management REST API Node.js
Tech Stack: Node.js, Azure Functions Core Tools, Cosmos DB SDK, VS Code

# Sample Azure Function (HTTP Trigger) snippet
import logging
import azure.functions as func
import json

async def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    order_id = req.route_params.get('orderId')
    req_body = req.get_json() if req.get_body() else None

    if order_id:
        # Logic to retrieve or process order by order_id
        response_message = f"Processing order with ID: {order_id}"
    elif req_body and 'items' in req_body:
        # Logic to create a new order
        response_message = "New order received and will be processed."
    else:
        response_message = "Please provide an order ID or order details in the request body."

    return func.HttpResponse(
         json.dumps({"message": response_message}),
         mimetype="application/json",
         status_code=200
    )
            

Real-time Data Ingestion API using Azure API for FHIR

Demonstrates creating a serverless API endpoint to ingest real-time healthcare data into Azure API for FHIR, enabling compliance and interoperability.

Azure API for FHIR Azure Functions FHIR Healthcare API Python
Tech Stack: Python, Azure Functions, Azure API for FHIR, FHIR R4

# Sample Python script for FHIR data validation
from fhirclient.models import patient, observation, bundle

def validate_fhir_resource(resource_data):
    # Placeholder for actual FHIR validation logic
    # using fhirclient or similar libraries
    if resource_data.get("resourceType") == "Patient":
        try:
            p = patient.Patient(resource_data)
            p.validate()
            return True, "Patient resource is valid."
        except Exception as e:
            return False, f"Patient validation failed: {e}"
    else:
        return False, "Unsupported resource type for this sample validation."

# Example usage:
# resource = {"resourceType": "Patient", "id": "example", "name": [{"family": "Smith", "given": ["John"]}]}
# is_valid, message = validate_fhir_resource(resource)
# print(f"Validation: {is_valid}, Message: {message}")
            

Product Catalog API with Azure App Service & Azure SQL Database

Build a scalable product catalog API using Azure App Service for hosting and Azure SQL Database for persistent storage. Includes examples for CRUD operations.

Azure App Service Azure SQL Database REST API CRUD C#
Tech Stack: C#, ASP.NET Core, Azure App Service, Azure SQL Database, Entity Framework Core

// Sample C# Controller action for GET /products
[ApiController]
[Route("api/[controller]")]
public class ProductsController : ControllerBase
{
    private readonly ProductCatalogDbContext _context;

    public ProductsController(ProductCatalogDbContext context)
    {
        _context = context;
    }

    // GET: api/Products
    [HttpGet]
    public async Task<ActionResult<IEnumerable<Product>>> GetProducts()
    {
        return await _context.Products.ToListAsync();
    }

    // ... other CRUD operations
}