Skip to content

feat: scaffold routes with explicit controller imports#46

Closed
eaguad1337 wants to merge 1 commit into
5.0from
claude/pr-review-e9oj5d
Closed

feat: scaffold routes with explicit controller imports#46
eaguad1337 wants to merge 1 commit into
5.0from
claude/pr-review-e9oj5d

Conversation

@eaguad1337

@eaguad1337 eaguad1337 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Context

Comes out of discussion #42: the default routes/web.py uses the string syntax "WelcomeController@show", and adopting an explicit controller-import style was proposed.

Finding

This syntax is already supported by the framework — no core changes are required. HTTPRoute._find_controller (src/masonite/routes/HTTPRoute.py:187-202) already resolves a Class.method reference passed directly via __qualname__/__module__. It is in fact the same mechanism Route.view/Route.redirect use internally (ViewController.show, RedirectController.redirect).

So this PR is a scaffold-only, non-breaking change.

Change

Updates the skeleton route files to import the controller class and pass the method directly:

from masonite.routes import Route

from app.controllers.WelcomeController import WelcomeController

ROUTES = [
    Route.get("/", WelcomeController.show).name("welcome"),
]

(The commented example in api.py is updated to match.)

Why

  • Enables go-to-definition, autocomplete and rename refactors in the IDE.
  • Typos / missing controllers fail at import time instead of at runtime with a warning + SyntaxError when the request hits the route.
  • Removes the "magic" string resolution via controllers_locations.

Compatibility

  • The string "Controller@method" form remains fully supported; existing apps are unaffected.
  • The Route.resource() / Route.api() helpers still take a string controller. Standardizing those to the class style would be a separate follow-up (the only point of inconsistency with this convention).

Closes #42.

Switch the default skeleton route files from the string
"WelcomeController@show" reference to importing the controller class and
passing the method directly (WelcomeController.show).

This is already fully supported by HTTPRoute._find_controller (the same
mechanism Route.view/Route.redirect use internally), so it is a non-breaking
scaffold-only change. The explicit style enables go-to-definition,
autocomplete, rename refactors and import-time errors for missing controllers
instead of runtime string resolution.

The string "Controller@method" form remains fully supported, as do the
Route.resource()/Route.api() helpers which still take a string controller.
@eaguad1337 eaguad1337 closed this Jun 9, 2026
@masonitedev masonitedev locked and limited conversation to collaborators Jun 9, 2026
@eaguad1337 eaguad1337 deleted the claude/pr-review-e9oj5d branch June 9, 2026 02:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant