Explorar el Código

首次提交FastAPI分层路由代码

lxwbite hace 2 meses
commit
cc19a88779

+ 10 - 0
.idea/.gitignore

@@ -0,0 +1,10 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 已忽略包含查询文件的默认文件夹
+/queries/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/

+ 35 - 0
1fastapi.py

@@ -0,0 +1,35 @@
+from fastapi import FastAPI
+
+# web服务器
+import uvicorn
+
+from api.book import api_book
+from api.cbs import api_cbs
+from api.zz import api_zz
+
+app = FastAPI()
+
+app.include_router(api_book, prefix="/book", tags=["book interface"])
+app.include_router(api_cbs, prefix="/cbs", tags=["cbs interface"])
+app.include_router(api_zz, prefix="/zz", tags=["zz interface"])
+
+@app.get("/")
+async def root():
+    return {"message": "Hello World"}
+
+
+@app.get("/get")
+async def get_test():
+    return {"method": "get method"}
+
+@app.post("/post")
+async def post_test():
+    return {"method": "post method"}
+@app.put("/put")
+async def put_test():
+    return {"method": "put method"}
+
+@app.delete("/delete")
+async def delete_test():
+    return {"method": "delete method"}
+

BIN
__pycache__/1fastapi.cpython-313.pyc


BIN
api/__pycache__/book.cpython-313.pyc


BIN
api/__pycache__/cbs.cpython-313.pyc


BIN
api/__pycache__/zz.cpython-313.pyc


+ 18 - 0
api/book.py

@@ -0,0 +1,18 @@
+from fastapi import APIRouter
+
+api_book = APIRouter()
+
+@api_book.get("/get")
+async def get_test():
+    return {"method": "get method"}
+
+@api_book.post("/post")
+async def post_test():
+    return {"method": "post method"}
+@api_book.put("/put")
+async def put_test():
+    return {"method": "put method"}
+
+@api_book.delete("/delete")
+async def delete_test():
+    return {"method": "delete method"}

+ 18 - 0
api/cbs.py

@@ -0,0 +1,18 @@
+from fastapi import APIRouter
+
+api_cbs = APIRouter()
+
+@api_cbs.get("/get")
+async def get_test():
+    return {"method": "get method"}
+
+@api_cbs.post("/post")
+async def post_test():
+    return {"method": "post method"}
+@api_cbs.put("/put")
+async def put_test():
+    return {"method": "put method"}
+
+@api_cbs.delete("/delete")
+async def delete_test():
+    return {"method": "delete method"}

+ 18 - 0
api/zz.py

@@ -0,0 +1,18 @@
+from fastapi import APIRouter
+
+api_zz = APIRouter()
+
+@api_zz.get("/get")
+async def get_test():
+    return {"method": "get method"}
+
+@api_zz.post("/post")
+async def post_test():
+    return {"method": "post method"}
+@api_zz.put("/put")
+async def put_test():
+    return {"method": "put method"}
+
+@api_zz.delete("/delete")
+async def delete_test():
+    return {"method": "delete method"}