GET request that uses more than one parameter

Viewed 382

If I build a simple FastAPI instance with a GET operation like this:

from fastapi import FastAPI

app = FastAPI()

@app.get("/users/{id_user}")
async def double(id_user: int):
    return {"result": id_user * 2}

if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8000)

If I run the API and immediately after that I use

r = requests.get("http://127.0.0.1:8000/users/8")
print(r.json())

I get correctly

{"result": 16}

Now I would like to do something like this:

@app.get("/users/{id_user}")
async def multiplication(id_user: int, k: int):
    return {"result": id_user * k}

How does requests.get() have to be written to get the desired result?

1 Answers
Related