File size: 1,082 Bytes
d32fe66
14fd956
d32fe66
dce9570
b916cdf
 
 
1299710
 
 
 
dce9570
 
 
 
2926b0b
c73e7bc
4b5a56f
dce9570
1299710
2926b0b
2d683a3
2926b0b
 
d32fe66
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from fastapi import FastAPI, HTTPException, Body, Request, File, UploadFile
from pydantic import BaseModel
from fastapi.responses import JSONResponse
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}

# Endpoint для загрузки файла
@app.post("/upload")
async def upload_file(file: UploadFile = File(...)):
    return JSONResponse(content={"filename": file.filename})