Implement backend API foundation

- Created FastAPI application with CORS middleware
- Defined Pydantic models (RoleDetectionRequest, RolesResponse, TTSRequest, ErrorResponse)
- Implemented /api/health endpoint
- Set up error handling middleware for validation and general exceptions
- Configured logging with INFO level
- Added test script to verify API functionality
- Validates Requirements: 9.1, 9.2, 9.4
This commit is contained in:
2025-12-09 00:57:46 +00:00
parent f4bc759007
commit 31da896e56
3 changed files with 107 additions and 4 deletions

26
backend/test_api.py Normal file
View File

@@ -0,0 +1,26 @@
#!/usr/bin/env python3
"""Simple test script for API foundation."""
import urllib.request
import json
def test_health():
"""Test health endpoint."""
response = urllib.request.urlopen('http://localhost:8001/api/health')
data = json.loads(response.read().decode())
print(f"✓ Health check: {data}")
def test_cors():
"""Test CORS headers."""
req = urllib.request.Request('http://localhost:8001/api/health',
headers={'Origin': 'http://localhost:5173'})
response = urllib.request.urlopen(req)
cors_origin = response.headers.get('Access-Control-Allow-Origin')
cors_creds = response.headers.get('Access-Control-Allow-Credentials')
print(f"✓ CORS Origin: {cors_origin}")
print(f"✓ CORS Credentials: {cors_creds}")
if __name__ == '__main__':
print("Testing API Foundation...")
test_health()
test_cors()
print("\nAll tests passed!")