How do I reference “params”?
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
This is the output of this test:
poetry run pytest -xsk task1
async_client = <httpx.AsyncClient object at 0x1076cb190>
@pytest.mark.asyncio
async def test_task1(async_client):
response = await async_client.get("/task1/greet/Jasmin")
assert response.status_code == 200
assert response.json() == "Hallo Jasmin, ich bin Emilia."
response = await async_client.get("/task1/greet/Stefan", params={"language": "en"})
assert response.status_code == 200
> assert response.json() == "Hello Stefan, I am Emilia."
E AssertionError: assert 'Hallo Stefan...h bin Emilia.' == 'Hello Stefan, I am Emilia.'
E - Hello Stefan, I am Emilia.
E ? ^ ^^^^
E + Hallo Stefan, ich bin Emilia.
E ? ^ ^^^^^^^
test_emilia.py:22: AssertionError
I am supposed to edit this code:
@app.get("/task1/greet/{name}", tags=["Task 1"], summary="👋🇩🇪🇬🇧🇪🇸")
async def task1_greet(name: str) -> str:
"""Greet somebody in German, English or Spanish!"""
return f"Hallo {name}, ich bin Emilia."
I don’t understand how to reference the “params={“language”:”en”}” in the test above. Assuming it’s being sent by the method “async_client.get()”,how do I pick that up in the method “task1_greet”?
Do I make a method argument like **kwargs, perhaps?
Thanks very much
Description
I need to write code that returns text depending on the language passed in “params”, and I don’t know how to reference “params” because I don’t understand how async_client.get corresponds to async def task1_greet.
I will explore kwargs but I’d still like to understand better how these two methods interact with each other.
Thank you
Operating System
macOS
Operating System Details
No response
FastAPI Version
latest
Python Version
latest
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
params keyword for parameter arrays - C# reference
By using the params keyword, you can specify a method parameter that takes a variable number of arguments. The parameter type must be...
Read more >C# Pass By Reference (Ref) with Examples - Tutlane
In c# passing parameter by reference means passing a reference of variable to the method. ... C# Pass By Reference · C# Out...
Read more >How to pass ref parameters in params - Stack Overflow
I want to pass n number of parameters to a method (both reference and normal). Here is my source code static void testParams(params...
Read more >params | Data Version Control - DVC
positional arguments: COMMAND diff Show changes in params between commits in the DVC repository, or between a commit and the workspace. Description. Parameters ......
Read more >Parameter-Passing Modes - cs.wisc.edu
Parameter a is a value parameter, b is a reference parameter, and c is a const-reference parameter. Value Parameters. When a parameter is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@peterelbert , take a look at this line of AlrasheedA’s code:
str
gets the default value ofNone
, making it optional, in case thelanguage
parameter isn’t set.@peterelbert Please close the issue if it worked.