FastAPI初了解
Main.py
from fastapi import FastAPI app = FastAPI() # 服务器在定义URL的时候,用了什么method,那么客户端在请求这个URL的时候就要用相同的method # get:从服务器上获取资源 # post:提交数据到服务器 # delete:删除服务器上的数据 # put:修改服务器上的数据 @app.get("/") # “”中填写路由 /:表示根路由 async def root(): # async:异步函数(协程) # await 访问数据库() 异步等待 return {"message": "Hello World"} @app.get("/hello/{name}") async def say_hello(name: str): return {"message": f"Hello {name}"}test_main.http
# Test your FastAPI endpoints #127.0.0.1:8000/ 服务器域名:端口号 GET http://127.0.0.1:8000/ Accept: application/json ### GET http://127.0.0.1:8000/hello/User Accept: application/json ###