《论术》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
本来准备学习,没想到直接用了,就用这篇文章纪念我的探索吧~~~
浙公网安备 33010602011771号