Fastapi: [QUESTION] Arbitrary (non-validated) query params in the form of variadic kwargs?

Created on 24 May 2019  路  4Comments  路  Source: tiangolo/fastapi

Description

I've noticed that I can't define some GET endpoint as such:

@app.get("/items/{item_id}")
def read_item(item_id: int, q: string = None, **kwargs):
    return {"item_id": item_id, "q": q, **kwargs}

Meaning, I can't define a route that will take arbitrary query params (i.e., not stipulated by the API schema itself). Am I missing something, or was this a conscious design decision?

question

Most helpful comment

@Datamance you can get the raw Request object directly and extract all the query parameters (defined or not): https://fastapi.tiangolo.com/tutorial/using-request-directly/

For those stumbling on this issue, here's an updated link: Using the Request Directly

All 4 comments

@Datamance you can get the raw Request object directly and extract all the query parameters (defined or not): https://fastapi.tiangolo.com/tutorial/using-request-directly/

馃憦 馃憦 馃憦 thank you!

Great! I'll then close this issue now. But feel free to add me comments or create new issues.

@Datamance you can get the raw Request object directly and extract all the query parameters (defined or not): https://fastapi.tiangolo.com/tutorial/using-request-directly/

For those stumbling on this issue, here's an updated link: Using the Request Directly

Was this page helpful?
0 / 5 - 0 ratings