[QUESTION] How to set a parameter from Body OR Query
See original GitHub issueFirst check
- 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.
Description
I am trying to setup a dependency that will accept a paramter from a Body or Query (it will be used as a dependency for POST and GET requests. I need to be able to look for the env parameter in either the Body or Query. Something like this maybe:
def testFactory(env: str = Body(...) or Query(...)):
testDict = {
'testenv1' = TestObject1(),
'testenv2' = TestObject2()
}
return testDict.get(env)
I’m an amateur programmer, so please let me know if I’m just not doing it right!
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Use parameters to ask for input when running a query
With the query open in Design view, on the Design tab, in the Show/Hide group, click Parameters. In the Query Parameters box, in...
Read more >REST API Design Best Practices for Parameter and Query ...
There are many ways in HTTP to add parameters to our request: the query string, the body of POST, PUT and PATCH requests,...
Read more >Creating a Parameter Query in Access - YouTube
In this SkillForge (www.skillforge.com) tutorial you'll learn how to create a parameter query in Microsoft Access. Learn more about Access ...
Read more >Use Parameters to Ask for User Input When Running a Query ...
In today's video, I'm going to show you how to prompt the user for some data, called a parameter, when running a query...
Read more >Working with Query Parameters in Rest Assured | REST API
?ISBN=9781449325862 - This is a string query parameter. The question mark denotes the start of a query string parameter.
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
Thanks for the help here @dbanty ! 🙇
Thanks for reporting back and closing the issue @taoofshawn 👍
You’re right, I think it would be better to keep “env” as a query parameter for all requests and just also accept a body for the other params for posts. I think it got (incorrectly) burned into my head somewhere to always use query for gets and form or body for posts. thanks @dbanty !