namespace for api version

This commit is contained in:
boyska 2021-09-24 00:52:55 +02:00
parent 4e9abf81b8
commit b95d96bc0f

View file

@ -111,7 +111,7 @@ def get_current_role(credentials: HTTPBasicCredentials = Depends(security)):
return "admin" return "admin"
@app.get("/counter/{cid}") @app.get("/v1/counter/{cid}")
async def get_value(cid: int): async def get_value(cid: int):
try: try:
val = counter_store.get(cid) val = counter_store.get(cid)
@ -121,7 +121,7 @@ async def get_value(cid: int):
return Value(counter=cid, value=val) return Value(counter=cid, value=val)
@app.post("/counter/{cid}/increment") @app.post("/v1/counter/{cid}/increment")
async def increment(cid: int, role: str = Depends(get_current_role)): async def increment(cid: int, role: str = Depends(get_current_role)):
if role != "admin": if role != "admin":
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN) raise HTTPException(status_code=status.HTTP_403_FORBIDDEN)
@ -129,7 +129,7 @@ async def increment(cid: int, role: str = Depends(get_current_role)):
return Value(counter=cid, value=val) return Value(counter=cid, value=val)
@app.websocket("/ws/counter/{cid}") @app.websocket("/v1/ws/counter/{cid}")
async def websocket_counter(websocket: WebSocket, cid: int): async def websocket_counter(websocket: WebSocket, cid: int):
await websocket.accept() await websocket.accept()
q: Queue = Queue() q: Queue = Queue()