fastapi用法

POST GET请求方法:

import time
import uvicorn
from fastapi import FastAPI, Body
from pydantic import BaseModel
app = FastAPI()
# POST请求
@app.post("/extraction/article/v1/getRegion")
async def getRegion(text_list=Body(None)):
    try:
        return {"success": True, "Msg": text_list}
    except Exception as e:
        return {"success": False, "Msg": str(e)}

#get请求
@app.get("/user/{id}")
def user(id):
    return {"id":id}

# get请求另一种方法
@app.get("/user")
def user(id,token=Header(None)):
return {"id":id,"token":token}
if __name__ == __main__: uvicorn.run(app=app, host="0.0.0.0", port=8000, workers=1)

结果展示

 

 

 fastapi用法

 

 fastapi用法

 fastapi用法

 

fastapi用法

上一篇:Linux开机自动挂载Windows分区


下一篇:Windwos下基于Qt的远程协助应用软件开发