How to pass path parameters to a function injected with Depends?

Viewed 38

In FastAPI, I want to have a parameter called db for my GET call, which receives a Session with a default value returned by a function injected with Depends.

@app.get("/computers", response_class=HTMLResponse)
async def read_computers(..., db: Session = Depends(get_custom_db))

where get_custom_db is defined as follows

async def get_custom_db(db_name: str, table_name: str):
    # CODE TO CONNECT TO A DATABASE

The problem is that I want to be able to pass PATH parameters instead of Query parameters to this get_custom_db function. Can I do this? How?

0 Answers
Related