Add simple API documentation endpoint

 Added Simple API Documentation:
- Created API_DOCS.md with comprehensive endpoint documentation
- Added /docs endpoint to serve formatted API documentation
- Updated /api endpoint to include documentation reference
- Simple HTML formatting for better readability

 Documentation Features:
- Complete endpoint descriptions with examples
- Request/response formats for all endpoints
- cURL and Python usage examples
- Error response documentation
- Model information and specifications

 Access Points:
- /api - Basic API info (JSON)
- /docs - Detailed documentation (HTML)
- API_DOCS.md - Raw markdown documentation

Simple, clean documentation without complex Swagger UI overhead.
This commit is contained in:
Aherobo Ovie Victor
2025-07-12 07:45:56 +01:00
parent 2426e71ed0
commit 0b7af4050e
2 changed files with 255 additions and 1 deletions
+41 -1
View File
@@ -88,16 +88,56 @@ def api_info():
'endpoints': {
'/': 'GET - Frontend interface or API information',
'/api': 'GET - API information (JSON)',
'/docs': 'GET - Detailed API documentation',
'/detect': 'POST - Upload image for memory module detection',
'/detect/hardcoded': 'GET - Process hardcoded test image',
'/detect/base64': 'POST - Process base64 encoded image',
'/health': 'GET - Health check'
},
'model_loaded': detector.model is not None,
'supported_formats': list(ALLOWED_EXTENSIONS)
'supported_formats': list(ALLOWED_EXTENSIONS),
'documentation': 'Visit /docs for detailed API documentation'
})
@app.route('/docs')
def api_docs():
"""Serve API documentation."""
try:
with open('API_DOCS.md', 'r') as f:
docs_content = f.read()
# Convert markdown to HTML for better display
html_content = f"""
<!DOCTYPE html>
<html>
<head>
<title>Memory Module Detection API - Documentation</title>
<style>
body {{ font-family: Arial, sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; line-height: 1.6; }}
pre {{ background: #f4f4f4; padding: 15px; border-radius: 5px; overflow-x: auto; }}
code {{ background: #f4f4f4; padding: 2px 4px; border-radius: 3px; }}
h1, h2, h3 {{ color: #333; }}
.nav {{ background: #e8f5e8; padding: 10px; margin-bottom: 20px; border-radius: 5px; }}
.nav a {{ margin-right: 15px; text-decoration: none; color: #0066cc; }}
.nav a:hover {{ text-decoration: underline; }}
</style>
</head>
<body>
<div class="nav">
<a href="/">🏠 Web Interface</a>
<a href="/api">📊 API Info</a>
<a href="/health">💚 Health Check</a>
</div>
<pre>{docs_content}</pre>
</body>
</html>
"""
return html_content
except FileNotFoundError:
return jsonify({
'error': 'API documentation file not found',
'message': 'Please ensure API_DOCS.md exists in the project directory'
}), 404
@app.route('/health', methods=['GET'])
def health_check():