Стартовый проект с роутерами
This commit is contained in:
0
backend-app/api/__init__.py
Normal file
0
backend-app/api/__init__.py
Normal file
7
backend-app/api/another_router.py
Normal file
7
backend-app/api/another_router.py
Normal file
@ -0,0 +1,7 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/hello")
|
||||
async def say_world():
|
||||
return {"msg":"Hello WORLD!"}
|
7
backend-app/api/main_router.py
Normal file
7
backend-app/api/main_router.py
Normal file
@ -0,0 +1,7 @@
|
||||
from fastapi import APIRouter
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/hello")
|
||||
async def say_hello():
|
||||
return {"msg":"hello"}
|
0
backend-app/core/__init__.py
Normal file
0
backend-app/core/__init__.py
Normal file
11
backend-app/core/settings.py
Normal file
11
backend-app/core/settings.py
Normal file
@ -0,0 +1,11 @@
|
||||
from pydantic_settings import BaseSettings
|
||||
from pydantic import BaseModel
|
||||
|
||||
class RunSettings(BaseModel):
|
||||
host: str = "0.0.0.0"
|
||||
port: int = 8000
|
||||
|
||||
class Settings(BaseSettings):
|
||||
run: RunSettings = RunSettings()
|
||||
|
||||
settings = Settings()
|
24
backend-app/main.py
Normal file
24
backend-app/main.py
Normal file
@ -0,0 +1,24 @@
|
||||
import uvicorn
|
||||
from fastapi import FastAPI, HTTPException
|
||||
from fastapi.responses import ORJSONResponse
|
||||
from core.settings import settings
|
||||
from api.main_router import router as main_router
|
||||
from api.another_router import router as another_router
|
||||
|
||||
|
||||
app = FastAPI(default_response_class=ORJSONResponse)
|
||||
|
||||
|
||||
#api/hello
|
||||
app.include_router(
|
||||
router=main_router,
|
||||
prefix="/api",
|
||||
tags=["Основной роутер"]
|
||||
)
|
||||
app.include_router(
|
||||
router=another_router,
|
||||
prefix="/another",
|
||||
tags=["Побочный роутер"]
|
||||
)
|
||||
if __name__ == "__main__":
|
||||
uvicorn.run(app, host=settings.run.host, port=settings.run.port)
|
Reference in New Issue
Block a user