FastAPI - Get keys and values from URL

by
Jeremy Canfield |
Updated: January 10 2025
| FastAPI articles
Let's say a request is submitted to the /Test route of your FastAPI application with the following parameters.
http://api.example.com/?foo=Hello&bar=World
Request can be used to get the values (Hello and World) from the keys (foo and bar).
from fastapi import FastAPI, Request
app = FastAPI()
@app.get("/")
async def root(request: Reqest):
return {"foo": request.query_params['foo'], "bar": request.query_params['bar']}
Did you find this article helpful?
If so, consider buying me a coffee over at