question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] How to set a parameter from Body OR Query

See original GitHub issue

First 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tiangolocommented, Jun 6, 2020

Thanks for the help here @dbanty ! 🙇

Thanks for reporting back and closing the issue @taoofshawn 👍

1reaction
taoofshawncommented, May 23, 2020

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 !

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found