Bootstrap FreeKB - FastAPI - Get keys and values from URL
FastAPI - Get keys and values from URL

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 090865 in the box below so that we can be sure you are a human.