Live2d Test Env

《论术》FastAPI 学习

from fastapi import FastAPI
from pydantic import BaseModel


app = FastAPI()

todos = [
    {"id": 1, "title": "Learn what a backend service is", "done": False},
]


class TodoCreate(BaseModel):
    title: str


@app.get("/health")
def health():
    return {"status": "ok"}


@app.get("/todos")
def list_todos():
    return todos


@app.post("/todos", status_code=201)
def create_todo(todo: TodoCreate):
    new_todo = {
        "id": len(todos) + 1,
        "title": todo.title,
        "done": False,
    }
    todos.append(new_todo)
    return new_todo

本来准备学习,没想到直接用了,就用这篇文章纪念我的探索吧~~~

posted @ 2026-08-31 22:40  致爱丽丝  阅读(6)  评论(0)    收藏  举报