Skip to content
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

Closed
asvetlov opened this issue Feb 26, 2018 · 13 comments
Closed

UrlDispatcher refactoring #2766

asvetlov opened this issue Feb 26, 2018 · 13 comments
Milestone

Comments

@asvetlov
Copy link
Member

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 in web.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 to abc.py.

Also I would add add_static and add_routes shortcuts to web.Application. People should use either URL table or RouteTableDef for defining routes, all others are internals. And we have app.add_subapp already, let's keep all casual route table definition in the same place. Other add_* 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.

@kxepal
Copy link
Member

kxepal commented Feb 26, 2018

Yay! As a aiohttp_traversal user, how this refactoring would affect on that project?

@asvetlov
Copy link
Member Author

aiohttp_traversal was never officially supported.
As we discussed with @zzzsochi and I mentioned in initial message the library could be rewritten to keep clean compatibility strategy with all future aiohttp versions.

The issue is mostly about declaring the status quo and adding two shortcuts: add_static and add_routes.

@hubo1016
Copy link
Contributor

Does It means that routes SHOULD be managed in a centralized pattern?

@asvetlov
Copy link
Member Author

@hubo1016 please elaborate

@hubo1016
Copy link
Contributor

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?

@asvetlov
Copy link
Member Author

add_routes should be a preferred way. All existing API will still alive forever.
app.add_routes could be called multiple times as app.router.add_routes does right now.

@asvetlov
Copy link
Member Author

Basically it is a way do skip .router property

@achimnol
Copy link
Member

achimnol commented Mar 4, 2018

Is this issue going to affect the design and implementation of #2756 ?
It would be nice if we have an easier way to extend URL dispatcher's behavior generally.

@asvetlov
Copy link
Member Author

asvetlov commented Mar 4, 2018

Not sure that extending url dispatcher by custom implementations is the right way to do things.
Overall construction is very delicate, hard to support all behavior right.

I think user should never implement own router.

No, the issue itself does not affect #2756, they are orthogonal

@aamalev
Copy link
Contributor

aamalev commented Aug 26, 2018

@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?

@asvetlov
Copy link
Member Author

@aamalev what resources do you register?
Could you provide an example?

@aamalev
Copy link
Contributor

aamalev commented Oct 2, 2018

@asvetlov Now I consider ways of development of aiohttp_apiset.SwaggerRouter. He serves on an algorithm similar to traversal.
Offhand there are two ways:

  • to adapt TreeResource to registration
  • factory the collecting RouteTableDef from the specification. But it will demand considerable processing.

@asvetlov
Copy link
Member Author

asvetlov commented Oct 3, 2018

But it will demand considerable processing.

Please elaborate

jcox-dev pushed a commit to ONSdigital/respondent-home-ui that referenced this issue Dec 12, 2018
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants