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", {"request": request, "text": "server is running"}) # Определяем единственный POST endpoint @app.post("/echo") def echo_text(text_request: TextRequest): # Просто возвращаем поле text из запроса return {"echoed_text": text_request.text}