A complete Data API Builder (DAB) quickstart template for MySQL, designed for API-only deployment. This project automatically generates both REST and GraphQL APIs over a MySQL database using Microsoft's Data API Builder.
This is a backend-as-a-service solution that:
- β Auto-generates REST & GraphQL APIs from your MySQL database schema
- β Complete local development environment with MySQL in Docker containers
- β No frontend dependencies - pure API deployment ready for any client
- β Sample AdventureWorks database with products, categories, and models
- β Azure-ready infrastructure templates for production deployment
REST API (http://localhost:5000/api):
GET /api/Product- List all productsGET /api/Product/id/{id}- Get specific productGET /api/ProductCategory- Product categoriesGET /api/ProductModel- Product models- Full CRUD operations on all entities
GraphQL API (http://localhost:5000/graphql):
- Single endpoint with full query/mutation support
- Schema introspection enabled
- Real-time subscriptions support
query {
products {
items {
ProductID
Name
ProductNumber
Color
ListPrice
}
}
}The project includes a MySQL version of AdventureWorks sample data:
- Product (295 items): Main product catalog with pricing, colors, categories
- ProductCategory (41 items): Hierarchical product categories
- ProductModel (128 items): Product model information with manufacturing details
- Visual Studio Code with Dev Containers extension
- Docker Desktop (running)
-
Clone and Open:
git clone <your-repo> cd dabmysql code .
-
Open in Dev Container:
- Press
F1and select "Dev Containers: Reopen in Container" - Wait 3-5 minutes for initial build and MySQL setup
- Press
-
Verify Database:
mysql -h mysql -u dabuser -p<your-pass-here> SalesLT SHOW TABLES; SELECT COUNT(*) FROM Product; exit
-
Start the API Server:
cd src/api dab start --config dab-config.json -
Test Your APIs:
- REST: http://localhost:5000/api/Product
- GraphQL: http://localhost:5000/graphql
- API Documentation: http://localhost:5000/api (shows available endpoints)
# Get all products
curl http://localhost:5000/api/Product
# Get specific product
curl http://localhost:5000/api/Product/id/1
# Get products by category
curl "http://localhost:5000/api/Product?\$filter=ProductCategoryID eq 1"
# Create a new product
curl -X POST http://localhost:5000/api/Product \
-H "Content-Type: application/json" \
-d '{
"Name": "Test Product",
"ProductNumber": "TP-001",
"ListPrice": 99.99,
"ProductCategoryID": 1
}'# Simple query
curl -X POST http://localhost:5000/graphql \
-H "Content-Type: application/json" \
-d '{"query": "{ products { items { ProductID Name ListPrice } } }"}'
# Query with filtering
curl -X POST http://localhost:5000/graphql \
-H "Content-Type: application/json" \
-d '{
"query": "query GetProductsByCategory($categoryId: Int) {
products(filter: { ProductCategoryID: { eq: $categoryId } }) {
items { ProductID Name ListPrice Color }
}
}",
"variables": { "categoryId": 1 }
}'- Hot reload: Changes to DAB config auto-restart the server
- Debug mode:
dab start --config dab-config.json --LogLevel Debug - Schema validation:
dab validate --config dab-config.json - MySQL client: Direct database access via
mysqlcommand
dabmysql/
βββ .devcontainer/ # Dev container configuration
βββ src/api/ # DAB API configuration and Dockerfile
βββ database/ # MySQL schema and seed data
βββ infra/ # Azure infrastructure templates
βββ postman/ # API testing collections
βββ README.md # This file
- dab-config.json: Data API Builder configuration
- docker-compose.yml: Local development services (MySQL + app)
- schema.sql & seed.sql: Database structure and sample data
Dev container won't start:
# Rebuild the container
F1 > "Dev Containers: Rebuild Container"MySQL connection fails:
# Check container status
docker ps
# View MySQL logs
docker logs devcontainer-mysql-1DAB API returns 500 errors:
# Validate configuration
cd src/api
dab validate --config dab-config.json
# Run in debug mode
dab start --config dab-config.json --LogLevel DebugPort already in use:
# Stop existing containers
docker-compose down
# Check what's using port 5000 or 3306
lsof -i :5000
lsof -i :3306- Import Collection: Import
postman/DAB-MySQL-API.postman_collection.json - Set Environment: Use
postman/Local-Environment.postman_environment.json - Update Variables: Set
baseUrltohttp://localhost:5000 - Run Tests: Try the "Get All Products" request first
Since this is an API-only deployment, you can integrate with any frontend:
const API_BASE = 'http://localhost:5000';
// Fetch products
const products = await fetch(`${API_BASE}/api/Product`).then(r => r.json());
// GraphQL with fetch
const graphqlQuery = await fetch(`${API_BASE}/graphql`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
query: '{ products { items { ProductID Name ListPrice } } }'
})
}).then(r => r.json());// Using axios
const products = await axios.get(`${API_BASE}/api/Product`);// Using HttpClient
constructor(private http: HttpClient) {}
getProducts() {
return this.http.get(`${API_BASE}/api/Product`);
}- One-command deployment with Azure Developer CLI (
azd up) - Azure Container Apps hosting with auto-scaling
- Azure Database for MySQL Flexible Server
- Azure Key Vault for secure credential management
- Production-ready configuration with authentication and CORS restrictions
- Monitoring and logging with Application Insights
- Authentication integration with Azure AD and custom providers
- Advanced querying with OData filters and GraphQL subscriptions
- Performance optimization guides and caching strategies
- CI/CD pipeline templates for automated deployments
- Data API Builder Documentation
- Azure Database for MySQL
- GraphQL Best Practices
- REST API Design Guidelines
MIT License - see LICENSE file for details.
Ready to build? Start with the Quick Start section above and have your API running in under 5 minutes! π