ODF/app/main.py

33 lines
687 B
Python
Raw Permalink Normal View History

2026-05-19 03:01:30 +00:00
"""FastAPI 主应用入口。
2026-05-14 08:04:47 +00:00
2026-05-19 03:01:30 +00:00
提供简单的 Hello World API 服务
2026-05-14 08:04:47 +00:00
"""
2026-05-19 03:01:30 +00:00
from fastapi import FastAPI
from app.services import get_greeting, get_system_info
2026-05-14 08:04:47 +00:00
app = FastAPI(
2026-05-19 03:01:30 +00:00
title="Simple Hello API",
description="一个最简单的 FastAPI 单体示例工程",
2026-05-14 08:04:47 +00:00
version="1.0.0",
)
2026-05-19 03:01:30 +00:00
@app.get("/")
async def root():
"""根路径,返回欢迎信息和系统信息。"""
return get_system_info()
2026-05-14 08:04:47 +00:00
2026-05-19 03:01:30 +00:00
@app.get("/hello/{name}")
async def say_hello(name: str):
"""根据传入的名字返回个性化问候。
2026-05-14 08:04:47 +00:00
2026-05-19 03:01:30 +00:00
Args:
name: 被问候者的名字
2026-05-14 08:04:47 +00:00
2026-05-19 03:01:30 +00:00
Returns:
包含问候语的 JSON 对象
"""
return {"message": get_greeting(name)}