from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": q}
这么方便就算了,然后打开http://127.0.0.1:8000/docs,能看到接口信息!超便捷!
GitHub地址:https://github.com/tiangolo/fastapi
本文介绍如何使用FastAPI框架快速搭建RESTful API服务,包括基本路由设置和参数解析。通过实例展示了如何定义路径参数和查询参数,并提供了运行服务后的文档访问方式。
1483

被折叠的 条评论
为什么被折叠?



