from fastapi import FastAPI, WebSocket from fastapi.responses import HTMLResponse import os app = FastAPI() html = """ Chat

WebSocket Chat

""" @app.get("/") async def get(): return HTMLResponse(html) @app.get("/env") async def env(): environment_variables = "

Environment Variables

" for name, value in os.environ.items(): environment_variables += f"{name}: {value}
" return HTMLResponse(environment_variables) @app.websocket("/ws") async def websocket_endpoint(websocket: WebSocket): await websocket.accept() while True: data = await websocket.receive_text() await websocket.send_text(f"Message text was: {data}")