Create Your First API in Azure API Management
Overview
Azure API Management (APIM) allows you to create, manage, secure, and document your APIs. This guide walks you through importing your first API and exposing it through the APIM gateway. By the end of this tutorial, you'll have a working API endpoint that external developers can consume.
What You'll Learn
- How to create an Azure API Management instance
- Different ways to import an API (OpenAPI, blank API)
- Adding operations to your API
- Testing your API through the Azure portal
- Understanding the URL structure
Prerequisites
- Azure subscription
- An existing API (or use mock)
Step 1: Create APIM Instance
Via Portal
- Search "API Management services"
- Click Create
- Configure:
- Name:
my-apim - Subscription: Your subscription
- Resource Group: Create or select
- Location: Choose region
- Pricing tier: Consumption (or Basic)
- Organization name: Your company
- Administrator email: Your email
- Name:
- Click Create
Wait ~30-40 minutes for deployment.
Step 2: Import an API
Option 1: OpenAPI (REST)
- Go to APIM → APIs
- Click + Add API
- Select OpenAPI specification
- Configure:
- Display name: "My API"
- Name:
my-api - Web service URL:
https://api.example.com - API URL suffix:
v1
- Click Create
Option 2: Blank API (Manual)
- Click + Add API
- Select Blank API
- Configure:
- Display name: "Manual API"
- Name:
manual-api - API URL suffix:
manual
- Click Create
Step 3: Add Operation
If using Blank API
- Select your API
- Click + Add operation
- Configure:
- Display name: "Get Products"
- Name:
GetProducts - URL: GET
/products - Description: Get all products
- Click Save
Step 4: Test the API
In Azure Portal
- Select API → Operation
- Click Test tab
- Click Send
Via URL
https://my-apim.azure-api.net/v1/products
API URL Structure
https://{apim-name}.azure-api.net/{suffix}/{path}
Example:
https://my-apim.azure-api.net/v1/products
Backend URL
The backend URL is where APIM forwards requests to.
Configure Backend
- Select API
- Click Settings
- Modify Web service URL
Real-Time Scenarios
Scenario 1: Calling Local Development API (localhost)
During development, you might want APIM to call your local machine. Use the APIM Management → Proxy → Test feature or set up a mock backend.
# For local development, configure:
Web service URL: http://localhost:5000
# Or use ngrok for external access:
Web service URL: https://your-ngrok-url.ngrok.io
Scenario 2: Data Processing Pipeline
APIM can orchestrate data processing workflows:
Client → APIM → Azure Function (validate)
→ APIM → Azure Function (transform)
→ APIM → Blob Storage (store result)
Scenario 3: Multiple Backend Services
Aggregate multiple APIs into one unified endpoint:
# Single APIM endpoint calling multiple backends
GET /api/orders → Backend: Order Service (http://orders.internal/api)
GET /api/inventory → Backend: Inventory Service (http://inventory.internal/api)
GET /api/shipping → Backend: Shipping Service (http://shipping.internal/api)
Scenario 4: Mock API for Testing
Create a mock response without a real backend:
- Select your API → Settings
- Set Web service URL to a non-existent URL (or leave empty)
- Add Mock responses to operations:
- Select Operation → Add policy → mock-response
- Return sample JSON responses
Common Issues & Solutions
| Issue | Solution |
|---|---|
| 502 Bad Gateway | Check backend URL is accessible |
| 401 Unauthorized | Verify subscription key or auth policy |
| 404 Not Found | Check API URL suffix and operation path |
| Timeout | Increase backend timeout in API settings |
Next Steps
- Explore Subscription Keys
- Learn about Calling Localhost from APIM in advanced topics
Azure Integration Hub - Beginner Level