-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Closed
Labels
Description
# main.py
from fastapi import FastAPI
import myroute
import myroute
app = FastAPI()
app.include_router(myroute.router)
@app.get("/")
async def root():
return {"message": "hello world!!"}# myroute.py
from fastapi import APIRouter
router = APIRouter(prefix="/prefix")
# you'd expect ws://localhost:800/prefix/ws to work but only ws://localhost:800/ws connects
@router.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await websocket.accept()
await websocket.send_text("hi")
await websocket.close()
# this works fine if you go to http://localhost:8000/prefix
@router.get("/")
def read_root():
return {"Hello": "World"}Description
Hi,
So with APIRouter(), the prefix path does not seem to be prepended to the websocket router path.
Not sure if its by design but if it is I feel like its quite misleading
Environment
-
OS: macOS Catalina 10.15.4
-
FastAPI Version: 0.63.0
-
Python version: 3.8.2
Reactions are currently unavailable