-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathmain.py
More file actions
63 lines (50 loc) · 1.54 KB
/
Copy pathmain.py
File metadata and controls
63 lines (50 loc) · 1.54 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
63
import os
import uvicorn
from fastapi import FastAPI
from fastapi.responses import JSONResponse
app = FastAPI(
title="FastAPI GitOps Starter",
description="A starter template for learning GitOps with FastAPI",
version="1.0.0",
root_path=os.getenv("ROOT_PATH", "/GitOps-Starter"),
)
@app.get("/")
async def root():
"""Root endpoint returning a welcome message."""
return {"message": "Welcome to FastAPI GitOps Starter!"}
@app.get("/health")
async def health_check():
"""Health check endpoint."""
return JSONResponse(
status_code=200,
content={"status": "healthy", "service": "fastapi-gitops-starter"},
)
@app.get("/api/items")
async def list_items():
"""Example endpoint to list items."""
return {
"items": [
{"id": 1, "name": "Item 1", "description": "First item"},
{"id": 2, "name": "Item 2", "description": "Second item"},
{"id": 3, "name": "Item 3", "description": "Third item"},
]
}
@app.get("/api/items/{item_id}")
async def get_item(item_id: int):
"""Example endpoint to get a specific item by ID."""
return {
"id": item_id,
"name": f"Item {item_id}",
"description": f"This is item number {item_id}",
}
@app.post("/api/items")
async def create_item(name: str, description: str):
"""Create a new item."""
return {
"id": 999,
"name": name,
"description": description,
"created": True
}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)