test-docker / main.py
ZakharZokhar's picture
Update main.py
2d683a3 verified
raw
history blame
No virus
819 Bytes
from fastapi import FastAPI, HTTPException, Body, Request
from pydantic import BaseModel
from fastapi.templating import Jinja2Templates
app = FastAPI()
# Определяем модель данных для запроса
class TextRequest(BaseModel):
text: str
# Подключаем шаблоны Jinja2
templates = Jinja2Templates(directory="templates")
# Главная страница с текстом "server is running"
@app.get("/")
async def read_root(request: Request):
return templates.TemplateResponse("index.html", {"text": "server is running"})
# Определяем единственный POST endpoint
@app.post("/echo")
def echo_text(text_request: TextRequest):
# Просто возвращаем поле text из запроса
return {"echoed_text": text_request.text}