[QUESTION] Accepting both GET and POST for the same route
See original GitHub issueHi there,
I’ve recently moved to FastAPI from Flask, and love the smoothness and speed of FastAPI. However, one thing I’m still trying to work out is how to accept GET and POST requests for the same routing, and to direct them both to the same function. In Flash I used to just use app.route and check the response.method.
For example, if I have some longFunction(request: Request), I’d like to route both GET and POST requests to it, but the decorator pattern seems to only allow one of these.
I’ve also tried the following, also to no avail (throws TypeError(“‘coroutine’ object is not iterable”)):
@app.get("/"):`
async def dummyFunction(request: Request):
return longFunction(request)
@app.post("/"):`
async def longFunction(request):
...
Issue Analytics
- State:
- Created 3 years ago
- Comments:6
Top Results From Across the Web
Handle both GET and POST request with same route in .net ...
Have you tried to create two separate functions. One for GET and the other for POST? You can still set the Route attribute...
Read more >Handle GET and POST Request in Express - CodeForGeek
GET and POST is two common HTTP Requests used for building REST APIs. Both of these calls ... We will use Express Router...
Read more >Difference between GET and POST Request in HTTP ... - Java67
GET, and POST is two of the most common HTTP methods you would hear or work on the web. Though both can be...
Read more >HTTP Request Methods – Get vs Put vs Post Explained with ...
In this article, we'll be discussing the get, put, and post HTTP methods. You'll learn what each HTTP method is used for as...
Read more >GET vs POST - Difference and Comparison | Diffen
HTTP POST requests supply additional data from the client (browser) to the ... The submission process for both methods begins in the same...
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 Free
Top 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
Looks like double decorators do work after all. My apologies
I do something that to only request get method. But I’m use FASTAPI second day, and I’m not sure this one