-
-
Notifications
You must be signed in to change notification settings - Fork 0
Reference Applications
Complete guide to the six reference API implementations demonstrating infrastructure integration patterns across multiple programming languages.
- Overview
- Available Implementations
- Common Features
- API Endpoints
- Getting Started
- Code Examples
- Testing
- API Patterns
The reference applications are production-ready examples demonstrating how to integrate with all DevStack Core infrastructure components. They showcase:
- Language-agnostic patterns
- Best practices for each ecosystem
- Identical API contracts across implementations
- Comprehensive testing strategies
- Learn patterns - See same concepts across different ecosystems
- Compare approaches - Different languages, same problems
- Choose your stack - Find what works for your team
- Validate consistency - Parity tests ensure identical behavior
Port: 8000 (HTTP), 8443 (HTTPS)
Container: dev-reference-api (172.20.0.100)
Directory: reference-apps/fastapi/
Features:
- OpenAPI spec auto-generated from code
- Type hints and Pydantic validation
- Async/await patterns
- Comprehensive test suite (254 tests)
- 84% code coverage
Access:
- Interactive docs: http://localhost:8000/docs
- OpenAPI spec: http://localhost:8000/openapi.json
- Health check: http://localhost:8000/health/all
Quick start:
docker compose up -d reference-api
curl http://localhost:8000/health/allPort: 8001 (HTTP), 8444 (HTTPS)
Container: dev-api-first (172.20.0.104)
Directory: reference-apps/fastapi-api-first/
Features:
- OpenAPI spec is source of truth
- Code generated from specification
- Guaranteed API contract compliance
- Parity tests with code-first (64 tests)
Access:
- Interactive docs: http://localhost:8001/docs
- OpenAPI spec: http://localhost:8001/openapi.json
- Health check: http://localhost:8001/health/all
Quick start:
docker compose up -d api-first
curl http://localhost:8001/health/allPort: 8002 (HTTP), 8445 (HTTPS)
Container: dev-golang-api (172.20.0.105)
Directory: reference-apps/golang/
Features:
- High-performance HTTP routing
- Concurrent request handling
- Structured logging
- Graceful shutdown
Access:
- Health check: http://localhost:8002/health/
- Vault info: http://localhost:8002/vault/info
Quick start:
docker compose up -d golang-api
curl http://localhost:8002/health/Port: 8003 (HTTP), 8446 (HTTPS)
Container: dev-nodejs-api (172.20.0.106)
Directory: reference-apps/nodejs/
Features:
- Modern async/await patterns
- Express middleware architecture
- Promise-based database clients
- Comprehensive error handling
Access:
- Health check: http://localhost:8003/health/
- Vault info: http://localhost:8003/vault/info
Quick start:
docker compose up -d nodejs-api
curl http://localhost:8003/health/Port: 8004 (HTTP), 8447 (HTTPS)
Container: dev-rust-api (172.20.0.107)
Directory: reference-apps/rust/
Features:
- High-performance async runtime
- Type-safe request handling
- Zero-cost abstractions
- Minimal resource footprint
Access:
- Health check: http://localhost:8004/health/
- Vault info: http://localhost:8004/vault/info
Quick start:
docker compose up -d rust-api
curl http://localhost:8004/health/Status: Scaffolding only
Directory: reference-apps/typescript-api-first/
Planned features:
- TypeScript with strict typing
- OpenAPI code generation
- Similar to Python API-First approach
All reference applications demonstrate:
- Retrieving secrets from Vault KV store
- Dynamic credential fetching
- TLS certificate usage
- Health check integration
- PostgreSQL - Relational data with connection pooling
- MySQL - Legacy database support
- MongoDB - Document storage patterns
- Redis Cluster - Distributed caching
- Connection pooling
- Cluster-aware operations
- SET/GET/DELETE operations
- RabbitMQ - Queue management
- Publishing messages
- Queue inspection
- Connection management
- Prometheus metrics export
- Structured logging
- Health check endpoints
- Request tracing
- TLS/HTTPS support
- Vault-managed certificates
- Secure credential handling
- CORS configuration
All implementations provide:
GET /health/ # Basic health
GET /health/all # All services (Python only)
GET /health/vault # Vault status
GET /health/postgres # PostgreSQL status
GET /health/mysql # MySQL status
GET /health/mongodb # MongoDB status
GET /health/redis # Redis cluster status
GET /health/rabbitmq # RabbitMQ statusGET /vault/info # Vault connection info
GET /vault/status # Vault seal status
POST /vault/secret # Store secret
GET /vault/secret/{key} # Retrieve secretGET /database/postgres/test # Test PostgreSQL connection
GET /database/mysql/test # Test MySQL connection
GET /database/mongodb/test # Test MongoDB connectionGET /redis/cluster/info # Cluster information
GET /redis/cluster/nodes # Node status
POST /redis/cache # Store value
GET /redis/cache/{key} # Retrieve value
DELETE /redis/cache/{key} # Delete valuePOST /messaging/publish # Publish to queue
GET /messaging/queue/{name} # Queue informationPOST /cache/set # Cache a value
GET /cache/get/{key} # Retrieve cached value
DELETE /cache/delete/{key} # Delete cached value
GET /cache/keys # List all keys# Start all at once
docker compose up -d reference-api api-first golang-api nodejs-api rust-api
# Or individually
docker compose up -d reference-api
docker compose up -d golang-api# Test all APIs
for port in 8000 8001 8002 8003 8004; do
echo "Testing port $port..."
curl -s http://localhost:$port/health/ | jq .
donePython implementations only:
- Code-First: http://localhost:8000/docs
- API-First: http://localhost:8001/docs
Provides:
- Try-it-now interface
- Request/response examples
- Schema definitions
- Authentication testing
Python (FastAPI):
from app.services.vault import VaultService
vault = VaultService()
secret = await vault.get_secret("postgres")
password = secret["password"]Go:
import "github.com/hashicorp/vault/api"
client, _ := api.NewClient(&api.Config{
Address: os.Getenv("VAULT_ADDR"),
})
secret, _ := client.Logical().Read("secret/data/postgres")
password := secret.Data["data"].(map[string]interface{})["password"]Node.js:
const vault = require('node-vault')({
endpoint: process.env.VAULT_ADDR,
token: process.env.VAULT_TOKEN
});
const secret = await vault.read('secret/data/postgres');
const password = secret.data.data.password;Python (FastAPI):
from app.db.postgres import get_db_connection
conn = get_db_connection()
cursor = conn.cursor()
cursor.execute("SELECT version()")
version = cursor.fetchone()Go:
import "database/sql"
import _ "github.com/lib/pq"
db, _ := sql.Open("postgres", connString)
var version string
db.QueryRow("SELECT version()").Scan(&version)Node.js:
const { Pool } = require('pg');
const pool = new Pool({ connectionString });
const result = await pool.query('SELECT version()');
const version = result.rows[0].version;Python (FastAPI):
from redis.cluster import RedisCluster
rc = RedisCluster(
host='redis-1',
port=6379,
password=redis_password
)
rc.set('key', 'value')
value = rc.get('key')Go:
import "github.com/redis/go-redis/v9"
rdb := redis.NewClusterClient(&redis.ClusterOptions{
Addrs: []string{"redis-1:6379", "redis-2:6379", "redis-3:6379"},
Password: redisPassword,
})
rdb.Set(ctx, "key", "value", 0)Python FastAPI:
# Run inside container
docker exec dev-reference-api pytest tests/ -v
# 254 tests, 84% coverageValidate that both Python implementations have identical APIs:
# From host (requires uv)
cd reference-apps/shared/test-suite
uv run pytest -v
# 64 tests validating consistency# Test all infrastructure
./tests/run-all-tests.sh
# Test specific API
./tests/test-fastapi.shCode-First (FastAPI):
- Write Python code with type hints
- OpenAPI spec auto-generated
- Fast development iteration
- Natural Python patterns
API-First (FastAPI):
- Design OpenAPI spec first
- Code generated from spec
- Contract-first development
- Guaranteed API compliance
Both approaches:
- Result in identical APIs
- Pass same parity tests
- Support same features
- Use same infrastructure
See API Patterns wiki page for detailed comparison.
-
Configuration Management
- Environment variables for config
- Vault for secrets
- Separate dev/prod settings
-
Error Handling
- Structured exceptions
- Consistent error responses
- Proper status codes
-
Connection Management
- Connection pooling
- Graceful shutdown
- Retry logic
-
Observability
- Health checks
- Structured logging
- Metrics export
-
Security
- No hardcoded credentials
- TLS support
- Input validation
Run benchmark suite:
./tests/performance-benchmark.shTypical results (requests/second):
- Rust: ~15,000 req/s
- Go: ~12,000 req/s
- Python FastAPI: ~5,000 req/s
- Node.js: ~8,000 req/s
Note: Numbers vary based on endpoint complexity and hardware.
-
Explore the code - Browse
reference-apps/<language>/ - Try the APIs - Use interactive docs at http://localhost:8000/docs
- Run the tests - See Testing Guide
- Build your own - Use as templates for your applications
- Compare patterns - See same problems solved differently
- Quick Start Guide - Get APIs running
- API Patterns - Code-first vs API-first
- Testing Guide - Running and writing tests
- Vault Integration - Using Vault in your apps