-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change Request method via middleware #3519
Comments
GitMate.io thinks the contributor most likely able to help you is @asvetlov. Possibly related issues are #2919 (Call method to clean middleware class), #3097 (aiohttp middleware and replacing a request in flight), #2225 (Middleware factory is run for every single request), #1392 (Issue with ClientSession.request('POST') method), and #491 (Handling basic auth with a middleware or a request annotation). |
Custom Routing Criteria looks like maybe it could work, but I would have to manually override all of my routes, I can't just say "if _method==DELETE, call |
The problem is: if you started to read request body ( |
If the request can't be modified, is there an elegant way to re-route the request as-is? The high-level goal is just that a
into every web.View individually |
you could create a base view such as class BaseView:
async def post(self):
data = await self.request.post()
if data.get('_method') == 'delete':
return await self.delete()
return await self.real_post()
async def real_post(self):
return await super().post() # will raise a 405
class View(BaseView):
async def delete(self):
...
async def real_post(self):
... or you can do some weird magic with metaclasses or |
Long story short
Browsers still only support GET and POST on HTML forms. I want to make a web front end for my REST API which includes DELETEing things, without having to use javascript. The standard suggestion here is to use POST and have a hidden field
<input type="hidden" name="_method" value="DELETE">
, and then have your middleware redirect that request to use the DELETE handler.Expected behaviour
There should be some way to do this
Actual behaviour
As far as I can tell this is impossible with aiohttp?
Steps to reproduce
in all cases the route handler for POST gets called instead of DELETE :(
Your environment
3.5.2 server
The text was updated successfully, but these errors were encountered: