Azure-Samples / Apim-Samples

Azure API Management Samples

Deploy high-fidelity Azure API Management infrastructures and experiment with real-world policies. Not too much, not too little. Just right.

Prefer slides?#

A browser-based slide deck walks you through the architectures and samples. Self-contained — save the page and present offline!

Open the slide deck

Infrastructures#

Each architecture is deployed with a single Jupyter notebook and torn down just as easily. These high-fidelity environments let you explore network patterns, private connectivity, and ingress design without building a full landing zone. When enabled, Container Apps backends use two MockAPI instances with authenticated dashboards and persistent Blob configuration. Simple API Management does not deploy MockAPI.

Samples#

Each sample is a focused, runnable lab. Open the notebook, press Run All, then poke at the policies. If an infrastructure is not already deployed, the notebook will guide you through creating one.

AuthX

Authentication and role-based authorisation against a mock HR API using JWT validation.

All infrastructures

AuthX Pro

Advanced authentication across multiple APIs with reusable policy fragments and an APIM product.

All infrastructures

Azure Maps

Proxy and shape calls to Azure Maps through APIM to centralise keys, quotas, and telemetry.

All infrastructures

Azure OpenAI v1 Migration

Create PAYG Azure OpenAI resources, test a dated legacy API, add and test v1 alongside it, and verify the original legacy contract again.

All infrastructures

Costing

Track and allocate API costs per business unit using subscriptions, Entra ID application tracking, and AI Gateway token/PTU tracking across both Azure OpenAI Chat Completions and Responses APIs, including streaming (SSE) token usage which is not simple to capture correctly in APIM.

All infrastructures

Dynamic CORS

Dynamic per-API CORS origin validation using custom policy fragments and a maintainable origin mapping.

All infrastructures

Egress Control

Control APIM outbound internet traffic by routing it through an Azure Firewall NVA in a hub/spoke topology with user-defined routes.

appgw-apim · appgw-apim-pe

General

Basic demonstration of sample setup and policy usage. The best first stop.

All infrastructures

Inference Failover

Route compatible Azure OpenAI models through priority and weighted APIM backend pools with focused LLM failover and token telemetry.

All infrastructures

Load Balancing

Priority and weighted load balancing, circuit breaking, and recovery using throttled endpoints on infrastructure-owned MockAPI backends. No extra container required.

apim-aca · afd-apim-pe

OAuth 3rd-Party

APIM stores and manages third-party OAuth tokens on the caller's behalf using Credential Manager.

All infrastructures

Secure Blob Access

Valet key pattern: APIM mints short-lived SAS tokens so callers never see storage credentials.

All infrastructures

Quick Start#

From clone to a running APIM lab in under ten minutes. Codespaces is the fastest route because Python, Azure CLI, and Bicep are already installed.

  1. Choose your setup

    Click Open in GitHub Codespaces above, or follow the local setup guide in the repository README.

  2. Deploy an infrastructure

    Open infrastructure/simple-apim/create.ipynb and press Run All. Deployment takes about five minutes.

  3. Run a sample

    Open any samples/*/create.ipynb and press Run All. The notebook will find your infrastructure and deploy onto it.

  4. Experiment

    Modify the policy XML, re-run the deployment cell, fire requests at the gateway, and watch the behaviour change.