-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
UrlDispatcher refactoring #2766
Comments
Yay! As a aiohttp_traversal user, how this refactoring would affect on that project? |
aiohttp_traversal was never officially supported. The issue is mostly about declaring the status quo and adding two shortcuts: |
Does It means that routes SHOULD be managed in a centralized pattern? |
@hubo1016 please elaborate |
You mean in the future, routes should always be added with add_routes right? Can it be called multiple times to add routes from different modules? |
|
Basically it is a way do skip |
Is this issue going to affect the design and implementation of #2756 ? |
Not sure that extending url dispatcher by custom implementations is the right way to do things. I think user should never implement own router. No, the issue itself does not affect #2756, they are orthogonal |
@asvetlov What fate awaits register_resource and AbstractResource? Is it possible to build compatibility on these interfaces? Maybe you should transfer AbstractResource and AbstractRoute to abc? |
@aamalev what resources do you register? |
@asvetlov Now I consider ways of development of aiohttp_apiset.SwaggerRouter. He serves on an algorithm similar to traversal.
|
Please elaborate |
* Pin aiohttp to version 3 to workaround issue with router usage See aio-libs/aiohttp#2766 * Update Pipfile Co-Authored-By: jcox-dev <me@jcox.tech> * Re-lock from updated Pipfile
Long text, please read carefully.
My initial idea was supporting both url mapper (implemented as
UrlDispatcher
class) and traversal.It follows Pyramid routing schema in some way.
Traversal approach should be done by alternative router implementation.
In fact the idea has failed: too many aiohttp based libraries assumes that router is url mapper. Moreover
app.add_subapp
explicitly ignores the fact of alternative implementation existence.Let's state the fact: the router is
UrlDispatcher
. I want to go even further: deprecate router argument inweb.Application
. If user need a custom url mapper based router usually it means he adds a couple helper methods for registering resources on top of existing.add_resource()
/.add_route()
. Better to solve the need by wrapping the whole application by user-specific class with appropriate methods.In practice it means raising up abstract classes from
web_urldispatcher.py
toabc.py
.Also I would add
add_static
andadd_routes
shortcuts toweb.Application
. People should use either URL table orRouteTableDef
for defining routes, all others are internals. And we haveapp.add_subapp
already, let's keep all casual route table definition in the same place. Otheradd_*
methods are considered as low-level API and will not be replicated in application.P.S.
traversal still could be built on top of url mapper: just make a resource for matching all paths like
'/{tail:.+}'
and do what you want in web handler.The text was updated successfully, but these errors were encountered: