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

Request: way to list registered routes #115

Open
daniel-v opened this issue Mar 21, 2021 · 4 comments
Open

Request: way to list registered routes #115

daniel-v opened this issue Mar 21, 2021 · 4 comments
Labels
enhancement New feature or request pkg:shelf_router Package shelf_router

Comments

@daniel-v
Copy link

Use case

Whenever I start the server, I'd like to log the list of registered routes. They tend not to change when I run my app, we can think of it as constant. This would allow me to print debug info during development and a way to verify changes in endpoints a CI script can use to verify changes post-deploy.

Current situation

Currently, Router has no way to allow access to added/mounted routes.

@sealed
class Router {
  final List<RouterEntry> _routes = [];

Proposal

A method or public function that can return an immutable list of RouterEntries. Something along these lines:

UnmodifiableListView<PrintableRouterEntry> getRoutes(Router router) {
  return UnmodifiableListView(router._routes.map((r) => PrintableRouterEntry(r)));
}

class PrintableRouterEntry {
  /* ... */
}
@daniel-v daniel-v added pending-triage Issue is pending triage pkg:shelf_router Package shelf_router labels Mar 21, 2021
@jonasfj jonasfj added enhancement New feature or request and removed pending-triage Issue is pending triage labels Mar 22, 2021
@jonasfj
Copy link
Member

jonasfj commented Mar 22, 2021

Uh, yeah, I think this could be a cool feature.

Maybe we can just make it static function like: Router.inspect(myRouter) -> Iterable<Route> (or something like that).

This would make even more sense if we allowed for bits of meta-data to attached to individual routes. Like whether or not it's part of the public API.


I'm not exactly sure how we would design this though..

@daniel-v
Copy link
Author

daniel-v commented Mar 23, 2021

With the turmoil around mirrors, I'd keep this simple. Another aspect I'd consider is that it should be AOT compilable.

Some folks use built in webserver in their Flutter apps to serve stuff for their webview. I use AOT+Docker on BE. (startup time matters).

I think, a simple solution now, that just gives me what I need, the routes, is preferred over designing a complex system. Later, we can always introduce a RouterInspector class which accepts a list of annotations to consider without breaking backward compatibility.

@isoos
Copy link
Collaborator

isoos commented Mar 26, 2021

The underlying data could be also used to collect route-specific statistics.

@daniel-v
Copy link
Author

daniel-v commented Mar 29, 2021

Q to those participating in the thread, if I submitted a PR with a minimal set of changes that I need, what are the chances that it would eventually land in a release? (I have CLA signed already)

I'd be happy to go back and forth to make sure that I do not introduce an API that would/will be used by a more complex system proposed in the thread too.

edit: I suppose at least I could express what I had in mind in a more specific way that could help triage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request pkg:shelf_router Package shelf_router
Projects
None yet
Development

No branches or pull requests

3 participants