桓楠百科网

编程知识、经典语录与百科知识分享平台

Python用fastapi来建立异步的web服务器

Python用fastapi来建立异步的web服务器

from fastapi import FastAPI
import uvicorn
app = FastAPI()
@app.get("/")
async def root():
    return {"message": "Hello"}
if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8080)

执行服务器程序

D:\code\python\http>python FastAPI1.py

INFO: Started server process [559768]

INFO: Waiting for application startup.

INFO: Application startup complete.

INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit)

运行结果

C:\Users\zjf>curl http://127.0.0.1:8080

{"message":"Hello"}

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言