-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
62 lines (47 loc) · 1.23 KB
/
main.py
File metadata and controls
62 lines (47 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import uvicorn
from fastapi import FastAPI
from pydantic import BaseModel
from datetime import datetime
app = FastAPI(
title="FastAPI Example",
description="Example application built with python-container-builder",
version="1.0.0"
)
class EchoRequest(BaseModel):
message: str
class EchoResponse(BaseModel):
echo: str
timestamp: str
@app.get("/health")
async def health_check():
"""Health check endpoint for container orchestration."""
return {"status": "healthy"}
@app.get("/")
async def root():
"""Root endpoint with basic information."""
return {
"message": "FastAPI Example",
"docs": "/docs",
"health": "/health"
}
@app.get("/time")
async def get_time():
"""Returns the current server time."""
return {
"current_time": datetime.now().isoformat(),
"timezone": "UTC"
}
@app.post("/echo", response_model=EchoResponse)
async def echo(request: EchoRequest):
"""Echoes back the message with a timestamp."""
return EchoResponse(
echo=request.message,
timestamp=datetime.now().isoformat()
)
if __name__ == "__main__":
uvicorn.run(
app,
host="0.0.0.0",
port=8000,
log_level="info"
)