FastAPI查看及API文档
一:查看
先写一个简单的小例子
from enum import Enum import uvicorn from fastapi import FastAPI class ModelName(str, Enum): tell_a = "1" tell_b = "2" tell_c = "3" app = FastAPI() @app.get("/models/{model_name}") async def get_model(model_name: ModelName): if model_name == ModelName.tell_a: return {"model_name": model_name, "msg": "hello one"} elif model_name.value == "3": return {"model_name": model_name, "msg": "hello three"} return {"model_name": model_name, "msg": "hello two"} if __name__ == '__main__': uvicorn.run("enum_test:app")
本例子中查看如访问 http://127.0.0.1:8000/models/2
二:交互式API文档 http://127.0.0.1:8000/docs
三:可选的API文档 http://127.0.0.1:8000/redoc
四:查看 openapi.json
本文来自博客园,作者:手可摘星辰/*,转载请注明原文链接:https://www.cnblogs.com/u-damowang1/p/16020393.html