Query Parameter
noun
say it: “KWEER-ee puh-RAM-ih-ter” /ˈkwɪri pəˈræmɪtər/
In FastAPI, a route function's parameter that isn't in the path, read from the part of the address after the ?, such as ?players=4.
What is Query Parameter?
Function parameters that aren't in the path become query parameters (?q=pasta&page=2). Give a default to make them optional.
@app.get('/search')
def search(q: str, page: int = 1):
return find_recipes(q, page)
In a sentence
- “Giving the query parameter a default of 1 made page optional.”
- “The shelf API filters games with a query parameter: /games?players=4.”
Level: Apprentice · More FastAPI terms at this level
Updated